//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");
}
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");
}

本文详细介绍了如何使用C#语言遍历GridView、Datagrid和DataList三种不同的控件,包括具体代码实现和关键步骤解析。
1920

被折叠的 条评论
为什么被折叠?



