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)
......
}
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)
......
}