The examples in this article describe the foreach traversal usage of the GridView, DataList, DataGrid three data controls in ASP.net. Share to everyone for your reference, specific as follows:
The GridView traversal is as follows:
foreach (GridViewRow row in gridview1.rows)
{
checkbox cb = (checkbox) row. FindControl ("CheckBox2");
if (CB). Checked = = True)
{
}
}
//datagrid traversal:
foreach (DataGridItem oitem in Itemsgrid.items)
{
checkbox ck1 = (checkbox) Oitem.findcontrol ("checkbox");
if (ck1. Checked = = True)
{
}
}
//datalist traversal
foreach (Datelistitem dl in Datalist1.items)
{
checkbox cb = (checkbox) DL. FindControl ("Checkboxid");
if (cb.checked) ...
}
Gridview:
for (int i=0 i <gridview.rows.count;i++)
{
label lbl = (Label) gridview.rows[i]. FindControl ("Label9");
}
Repeater:
for (int i=0 i < repeater.items.count;i++)
{
Label lbl = (Label) repeater.items[i]. FindControl ("Label9");
}
DataList:
for (int i=0 i < datalist.items.count;i++)
{
Label lbl = (Label) datalist.items[i]. FindControl ("Label9");
}
More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.