How to Fetch All The rows of gridview when paging is enabled?.
it is allowing to fetch only current fetch rows not entire gridview rows.
You can use the Commands Below which I'm using it in my projects. Its logic is so simple, you go through all pages and in every page you go through all rows. You can also get your current page before doing this and after looping all you can get back there ;)
//Get Current Page Index so You can get back here after commands
int a = GridView1.PageIndex;
//Loop through All Pages
for (int i = 0; i < GridView1.PageCount; i++)
{
//Set Page Index
GridView1.SetPageIndex(i);
//After Setting Page Index Loop through its Rows
foreach (GridViewRow row in GridView1.Rows)
{
//Do Your Commands Here
}
}
//Getting Back to the First State
GridView1.SetPageIndex(a);
We disable paging temporarily and will re-bind the grid so that now we have access to all records in the datasource not just current page records.
Once gridview is binded with all records, you can iterate through gridview rows.
Once we are done with our task, we re-enable paging and rebind the grid.
Here the way to tackle with your condition:
protected void Page_Load(object sender, EventArgs e)
{
GridView2.AllowPaging = false;
GridView2.DataBind();
// You can select some checkboxex on gridview over here..
GridView2.AllowPaging = true;
GridView2.DataBind();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With