我收到了幾個複選框,但我只希望文本「新桌面」和「新筆記本電腦」只能選擇2個。我希望它可以在C#中完成。從2中選擇1複選框
<asp:CheckBoxList ID="Service1" runat="server"
Width="251px" >
<%--onselectedindexchanged="checkBox1_CheckedChanged"--%>
<asp:ListItem text="New Login ID & Email Address" ></asp:ListItem>
<asp:ListItem text="New Desktop" Value="2" oncheckedchanged="checkBox1_CheckedChanged" ></asp:ListItem>
<asp:ListItem text="New Notebook" Value="3" oncheckedchanged="checkBox2_CheckedChanged"></asp:ListItem>
<asp:ListItem text="New Mouse"></asp:ListItem>
<asp:ListItem text="New Keyboard"></asp:ListItem>
<asp:ListItem text="New Printer"></asp:ListItem>
</asp:CheckBoxList>
//.cs pages
protected void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (Service1.Items[2].Selected == true)
{
Service1.Items[3].Enabled = false;
}
}
protected void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (Service1.Items[3].Selected == true)
{
Service1.Items[2].Enabled = false;
}
}
這也許能幫助 - http://stackoverflow.com/a/10553349/6538824 –
謝謝Giorgi的,因爲我還是一個初學者我真的不明白寫的方式。 – Johnny
你上面給出的代碼不工作? –