Thursday, October 23, 2008

How to loop through all rows in girdview with paging

Using Datatable/DataView/Dataset/... as datasource:

//Suppose we are using DataTable as Datasource
DataTable dt = GridView1.DataSource as DataTable;
foreach (DataRow dr in dt.Rows)
{
//do something
}

Using SqlDataSource control as a datasource:

//SqlDataSource1 is a SqlDataSource control
DataView view = (DataView)SqlDataSource1.Select(dsaArgs);
DataTable dt = view.ToTable();
foreach (DataRow dr in dt.Rows)
{
//do something
}

No comments: