同时想问问你下面的翻页是GirdView自带的吗?
我想起来了,你要在后台定义如下方法:
(CheckBox)GridView的ID.Rows[i].FindControl("CheckBox的ID")
具体的方法:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
GridViewRow gvr = (GridViewRow)((CheckBox)sender).Parent.Parent;
string values= GridView1.DataKeys[gvr.RowIndex].Value.ToString();
}
//自定义模板编辑时
if(e.CommandName == "myuc")
{
int rowindex = ((GridViewRow)((LinkButton)e.CommandSourece).NamingContainer).RowIndex;
string id = GridView.DataKey[rowIndex].Value.Tostring();
//你需要执行的函数
}
String wid = "";
foreach (GridViewRow gvr in this.GridView1.Rows)
{
Control ctl = gvr.FindControl("CheckBox1");
CheckBox ck = (CheckBox)ctl;
if (ck.Checked)
{
TableCellCollection cell = gvr.Cells;
wid +=cell[2].Text + ",";
}
}
Response.Write(wid);
在前台写js获取到勾选的checkbox的值,然后将值放入隐藏域中,后台从隐藏域中得到勾选的值。
先获取该行该列的controls,然后根据类型选择 checkbox
复选框是动态生成的还是gridview自带的