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"
);
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步