復制代碼 代碼如下:
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)
{
}
}