Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Fetch All Rows Of Gridview When Paging is Enabled??

Tags:

asp.net

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.

like image 409
Kunal Shah Avatar asked Feb 15 '13 09:02

Kunal Shah


2 Answers

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);
like image 109
Inside Man Avatar answered Nov 13 '22 14:11

Inside Man


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(); 
}
like image 8
Vishal Suthar Avatar answered Nov 13 '22 14:11

Vishal Suthar