0

I have a gridview (gvClient) containing checkboxes (chkSelect). I have enabled paging for same grid and I have lots of data to show. But I am facing the problem, that while retrieving all data from gridview, I am getting only current page gridview data. My code:

foreach (GridViewRow gvrClient in gvClient.Rows)  // gvClient.Rows not giving all gridview rows
{
     cbSelect = (CheckBox)gvrClient.FindControl("chkSelect");
     if (cbSelect.Checked == true)
     {
        //Operations
     }
}

I got following solution on google to use, but it is not working.

 gvClient.AllowPaging=false;
 gvClient.DataBind();
foreach (GridViewRow gvrClient in gvClient.Rows)  // gvClient.Rows not giving all gridview rows
{
    cbSelect = (CheckBox)gvrClient.FindControl("chkSelect");
    if (cbSelect.Checked == true)
    {
        //Operations
    }
 }
 gvClient.AllowPaging=true;
 gvClient.DataBind();

Any help on this?

user2493287
  • 255
  • 1
  • 4
  • 16

1 Answers1

0

you can not access all pages in c#. and by the way, why you want to access complete data of grid? as when you change a page, grid gets reset again. grid does not maintain page state data. you can access the same data from a datatable/dataset which you have set as source of data to that grid..

  • I agree Abhijeet, suppose I have 20 records in gridview and out of them 10 records checked and 10 unchecked by Checkbox which is in gridview itself. So, if I use datatable/dataset, How can I get check and uncheck records of gridview? – user2493287 Feb 06 '15 at 08:43
  • see, if you have 20 total records. 10 records on page1 and 10 records on page2 and suppose you are seeing page 1. then you can only access 10 check boxex which are on page1. one more thing. suppose user goes to page 1 and check 3 check boxes out of 10 and then go to page 2 and check 5 check bozex on page2. and if again user comes to page1. then those 3 check boxes will not remain check, user will see all check boxs are uncheck.. – Abhijeet Bagul Feb 07 '15 at 04:05
  • grid itself will hold pagewise data. grid will only hold data of page wich you are seeing. so my point is that. grid is not holding that data so there is no point to acess all pages of grid. – Abhijeet Bagul Feb 07 '15 at 04:08