首先,您的CheckBoxList將需要AutoPostBack設置爲true。
我認爲,關鍵您所渴望的是什麼
CheckBoxList1.Items.FindByText(service).Enabled = false;
或這個工程太
CheckBoxList1.Items.FindByText(service).Attributes.Add("disabled", "disabled");
的情況下,它可能是這個樣子:
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"
onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
</asp:CheckBoxList>
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
//first reset all to enabled
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
CheckBoxList1.Items[i].Attributes.Remove("disabled", "disabled");
}
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
//get list of items to disable
string selectedService = CheckBoxList1.Items[i].Text;
List<string> servicesToDisable = getIncompatibleFor(selectedService);//this function is up to u
foreach (string service in servicesToDisable)
{
CheckBoxList1.Items.FindByText(service).Attributes.Add("disabled", "disabled");
}
}
}
}
你試圖做一個單選按鈕列表? 我沒有明白你的意思 – Shimmy 2009-05-21 02:17:25