protected void Page_Load(object sender, EventArgs e)
 {
     MediaArtists dal = new MediaArtists(StoredData);
     if (!Page.IsPostBack)
     {
         PageAndBind(GridView1);
     }
 }
        private void PageAndBind(GridView gv)
        {
            IList<Object> list = new List<Object>();
            int pageSize = 2;
            int startRow = (gv.PageIndex * pageSize);

            MediaArtists artists_obj = new MediaArtists();
            IList<Media_Artists> data =
                artists_obj.LoadDatedItemsByPage(startRow, pageSize, GridViewSortBy, GridViewSortAscending);
            //copy data into generic list
            foreach (Media_Artists item in data)
                list.Add(item);
            int count = artists_obj.LoadDatedItemsCount(); //you could cache this
            //here's the bit where we use create an ODS in code to fill the gridview with paged data
            CommonLibrary.UI.GridView.GridViewFiller.Fill(gv, list, count, pageSize);
        }        
        private int UpdateData()
        {
            string user_id = Session["UserId"].ToString();
            string artist_name = txtArtistName.Text;
            string description = txtDescription.Text;
            string status = rdlStatus.SelectedValue;

            /*** UPLOAD ************************************************************************************************************/
            string[] FileImg = new String[2];
            string front_image = string.Empty; string main_image = string.Empty;
            string front_path = Server.MapPath(upload_front_image_dir);
            string main_path = Server.MapPath(upload_main_image_dir);

            string Orginal_front_image = ViewState["FrontImage"].ToString();
            string Orginal_main_image = ViewState["MainImage"].ToString();

            //if (FileUpload1.HasFile)
            if (Session["FileUpload1"] != null && Session["FileUpload1"].ToString() != string.Empty)
            {
                FileHandleClass file_bj = new FileHandleClass();
                FileImg = file_bj.upload_front_main_image(FileUpload1, front_path, main_path, 120, 120);
                main_image = FileImg[0];
                front_image = FileImg[1];
                //System.Drawing.Image img1 = System.Drawing.Image.FromFile(front_path+ "/" + front_image);                
                imgPhoto.ImageUrl = upload_front_image_dir + "/" + front_image;
                string folderchild = Orginal_front_image.Substring(0, 10);
                DeleteFrontImage(Orginal_front_image);
                DeleteMainImage(Orginal_main_image);
            }
            else
            {
                front_image = Orginal_front_image;
                main_image = Orginal_main_image;
            }
            ////========================================================================================================================

            MediaArtists artist_obj = new MediaArtists();
            int i = artist_obj.Update(_idx, user_id, artist_name, front_image, main_image, description, status);
            return i;
        }
        private int AddData()
        {
            string user_id = Session["UserId"].ToString();
            string artist_name = txtArtistName.Text;
            string description = txtDescription.Text;
            string status = rdlStatus.SelectedValue;

            /*** UPLOAD ************************************************************************************************************/
            string[] FileImg = new String[2];
            string front_image = string.Empty; string main_image = string.Empty;
            string front_path = Server.MapPath(upload_front_image_dir);
            string main_path = Server.MapPath(upload_main_image_dir);

            if (FileUpload1.HasFile)
            {
                FileHandleClass file_bj = new FileHandleClass();
                FileImg = file_bj.upload_front_main_image(FileUpload1, front_path, main_path, 120, 120);
                main_image = FileImg[0];
                front_image = FileImg[1];
                //System.Drawing.Image img1 = System.Drawing.Image.FromFile(front_path+ "/" + front_image);                
                imgPhoto.ImageUrl = upload_front_image_dir + "/" + front_image;
            }
            ////========================================================================================================================

            MediaArtists artist_obj = new MediaArtists();
            int i = artist_obj.Insert(user_id, artist_name, front_image,main_image, description, status);
            return i;
        }
        private void LoadData()
        {
            MediaArtists artist_obj = new MediaArtists();
            Media_Artists entity = artist_obj.GetDetails(_idx);

            string FrontImage = entity.FrontImage;
            string MainImage = entity.MainImage;
            imgPhoto.ImageUrl = upload_front_image_dir + "/" + FrontImage;
            ViewState["FrontImage"] = FrontImage;
            ViewState["MainImage"] = MainImage;

            txtArtistName.Text = entity.ArtistName;
            txtDescription.Text = entity.Description;
            string Status = entity.Status;
            PopulateStatus2DDL(Status);
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {           
            GridView gv = (GridView)sender;
            //to get index and row
            int rowIndex = e.RowIndex; //here we have the row directly
            //GridViewRow row = gv.Rows[rowIndex]; //the row
            int key = (int)gv.DataKeys[rowIndex][0]; //int key = Convert.ToInt32(gv.DataKeys[e.RowIndex].Values[0].ToString());
            //string UserId = Session["UserId"].ToString();
            //string Status = "1";
            MediaArtists artists_obj = new MediaArtists();
            artists_obj.Delete(key);
            //artists_obj.UpdateStatus(UserId, key, Status);
            if (rowIndex == 0 && gv.Rows.Count == 1)
                gv.PageIndex = gv.PageIndex - 1; //only 1 item on page- page back
            PageAndBind(gv); //load the new information

        }