我有一個gridview,我已經通過編程方式添加了複選框。 我做一個foreach循環內創建複選框時以下,從而使檢查時,他們觸發一個事件,只允許檢查一個複選框 - asp.net c#
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?
}
感謝您的提前回答。
你的問題是什麼? – Ahmad
那麼,首先請說明爲什麼不使用單選按鈕而不是複選框?如果你堅持,那麼你可以使用jquery/javascript實現相同的功能。 –
使用單選按鈕 –