ASP.NET中GridView控件的问题

2025-02-24 23:01:11
推荐回答(2个)
回答1:

如果只有第一列使用选中框..
则可以使用下面的办法..

ArrayList arr=new ArrayList();
CheckBox ck = new CheckBox();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if(ck.Checked==true)
{
arr.Add(GridView1.Rows[i].Cells[1].Text);
}
}

如果主键绑定使用了模板
则类似于
ArrayList arr = new ArrayList();
CheckBox ck = new CheckBox();
TextBox txt = new TextBox();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (ck.Checked == true)
{
txt = (TextBox)GridView1.Rows[i].Cells[1].FindControl("TextBox1");
arr.Add(txt.Text);
}
}

回答2:

GridView1.Rows[0].Cell[0].Text;