How to get all gridview rows when paging is enabled?

How to get all gridview rows when paging is enabled?

it allows you to retrieve only the current selection rows, not entire gridview rows.

+4
source share
6 answers

We will temporarily disable paging and bind the grid again so that we now have access to all the records in the data source, and not just the current records.

When a gridview is bound to all records, you can iterate through the rows of gridview.

As soon as we finish our task, we will turn on paging again and regroup the grid.

Here is a way to handle 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(); } 
+6
source

You can use the commands below, which I use in my projects. Its logic is so simple that you look at all the pages and on every page you look at all the lines. You can also get your current page before doing this, and after the loop is all you can go 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); 
+7
source

Use the following code and disable paging GridView

GridView1.AllowPaging = false; GridView1.DataBind ();

on Loading a page or some other event where you want to show all your rows Gridview

+6
source

Before the function of retrieving data from the grid simply writes

 yourGridName.AllowPaging=false; 

and after receiving the data write

 yourGridName.AllowPaging=true; 

If your function is GetDataFromGrid (), you should go like this:

 protected void Page_Load(object sender, EventArgs e) { yourGridName.AllowPaging=false; GetDataFromGrid() yourGridName.AllowPaging=true; } 
+4
source

You cannot display all lines when paging is enabled. But you can do Allowpaging=false; in codebehind in pageload or in some case.

 protected void Page_Load(object sender, EventArgs e) { Gridviewname.AllowPaging=false; } 

or

 Protected Void some event(object sender,Eventargs e) { Gridviewname.AllowPaging=false; } 
+3
source

It is best to place the hidden field at the top of the page (outside the gridview) and click the checkboxes, you should put the associated identifier or some value in comma-separated format in the hidden field. When you submit the form, you can separate the string value of the hidden field with a comma as a separator and there you go.

+2
source

All Articles