我有一个网格视图,在其中以编程方式添加了复选框。 在 foreach 循环内创建复选框时,可以按照以下操作,使其在选中时触发事件:
cbGV = new CheckBox();
cbGV.ID = "cbGV";
cbGV.AutoPostBack = true;
cbGV.CheckedChanged += new EventHandler(this.cbGV_CheckedChanged);
基本上,当我想要触发事件时,我需要以下内容:
protected void cbGV_CheckedChanged(object sender, EventArgs e)
{
//gets the current checked checkbox.
CheckBox activeCheckBox = sender as CheckBox;
foreach (GridViewRow gvr in GridView1.Rows)
{
//this code is for finding the checkboxes in the gridview.
CheckBox checkBox = ((CheckBox)gvr.FindControl("cbGV"));
//so basically, right here i'm confused on how i should compare the if/else logic, how i should compare and disable every other checkbox if the current checkbox is checked. Any ideas gues?
}
感谢您提前回答。