Click here to Skip to main content
15,036,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to read the values from a grid view control ?
foreach (GridViewRow row in grdSearchresult.Rows)


This is what am doing but the problem is, its fetching only items which are shown in grid, ie i have enabled pagination so grid will show only 10 items per page.
The above code is fetching only that 10 values but instead of that i need to fetch all the records in that grid.

Eg: Grid result contains 30 records
Since pagination is enabled it will show only 10 items.So when i do loop its looping through only this 10 items but i want to loop through all the items(in this case 30 items ).
ZurdoDev 8-Oct-14 10:49am
You need to loop through your data then since the grid does not have all 30 rows.

Loop through the binding source from which your are binding the gridview

Before foreach disable paging using grdSearchresult.AllowPaging = false;
grdSearchresult.AllowPaging = false;
foreach (GridViewRow row in grdSearchresult.Rows)
grdSearchresult.AllowPaging = true;

and after foreach enable paging using grdSearchresult.AllowPaging = true;

or Save the datasource of this gridview into a hiddenfield or session and access.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900