2014年7月13日 星期日

[RESOLVED] Looping Through Gridview


Anyone have any information on how to loop through all the pages of a gridview?



Set paging false on gridview


Bind gridview with datasource


than loop through all the row like


GridView.Paging = false;
GridView.DataSource = yourdatasource;
GridView.DataBind();
Foreach(var row in GridView.Rows)
{
//Do something
}



Jogginjoe


Anyone have any information on how to loop through all the pages of a gridview?


By the way you can loop through your datasource for all the records or you can use rowdatabound event 



in case of pagging you can iterate over the current page only,  so either set pagging to false or instead iterate over actual data-source. thanks



yeah but i have 1.7 million entires and i get a error like system.exception.outofmemory i have have paging set to true to avoid this issue0



Hi,


For How to loop through all the rows in all the pages of a GridView:


One simple way to loop through all the rows in all the pages of a GridView is to access its DataSource. In this example, we will loop through the SQLDataSource to retrieve all the
rows in a GridView and access its cell value:


protected void Button1_Click(object sender, EventArgs e)
{
DataSourceSelectArguments dsaArgs = new DataSourceSelectArguments();
DataView view = (DataView)SqlDataSource1.Select(dsaArgs);
DataTable dt = view.ToTable();
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
string s = dt.Rows[i][j].ToString();
}
}
}

Hope it can help you.


Best Regards,

Amy Peng 


 


沒有留言:

張貼留言