Is it possible to loop through a gridview with more than one page, the gridview I’m looking at has a pageSize of 20, there are say 26 records (over two pages) and I want to be able to loop though all the records.
For Each row As GridViewRow In GridView.Rows
.
.
.
Next row
The count of the above is only 20 as the pageSize is set to 20, I can see that the pagecount is 2 but how do you loop through the next page in a gridview? Or would I have to just iterate through the orginal datasource?
You have two options: 1) use the original data source that has all rows for your grid (a very unoptimized solution!) or 2) have the stored procedure that gets the result set from the database be optimized for paging. If you use option one, then you’ll have to rebind your grid with the current page (a common solution would be to use linq and query your data source). If you use option two, you’ll have access to the results set from the database. Either way, you’ll eventually need to use the ItemDataBound event and and then you can iterate through each item in your grid.