本文实例讲述了ASP.NET中GridView、DataList、DataGrid三个数据控件foreach遍历用法。分享给大家供大家参考,具体如下:
//gridview遍历如下:
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBox2");
if (cb.Checked == true)
{
}
}
//datagrid遍历:
foreach (DataGridItem oItem in ItemsGrid.Items)
{
CheckBox ck1 = (CheckBox)oItem.FindControl("CheckBox");
if (ck1.Checked == true)
{
}
}
//datalist遍历
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");
}
希望本文所述对大家asp.net程序设计有所帮助。
到此这篇关于ASP.NET中GridView、DataList、DataGrid三个数据控件foreach遍历用法示例就介绍到这了。健康的身体是实目标的基石。更多相关ASP.NET中GridView、DataList、DataGrid三个数据控件foreach遍历用法示例内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!




