代码如下:
int intCount = this.GridView1.Rows.Count; //总行数
for (int i = 0; i < intCount; i++)
{
Label1.Text = ((HyperLink)GridView1.Rows[i].Cells[0].Controls[0]).Text.ToString().Trim();
}
for (i = 0; i < GridViewID.Rows.Count; i++)
{
CheckBox chkVote = (CheckBox)GridView1.Rows[i].FindControl("CheckBox2");
}
上面都是利用for来遍历ridview控件,下面我来利用foreach来遍历控件。
复制代码代码如下:
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBox2");
if(cb.Checked==true)
{
}
}