0
我使用CheckBoxList
來顯示一組業務單位。我想限制選擇最多5個項目,並且如果用戶選擇第6個項目,那麼我應該顯示一個警報並取消選擇第6個項目。CheckBoxList - 將選擇限制到特定數字
的控制是如下:我使用
<asp:CheckBoxList ID="ckBLBusinessUnits" onclick="loader(this.id);" runat="server" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="ckBLBusinessUnits_SelectedIndexChanged"></asp:CheckBoxList>
JS功能是:
function loader(controlID) {
modal = document.getElementById('loadingImage');
modal.style.display = "block";
if (controlID == "ckBLBusinessUnits")
{
if (($('#ckBLBusinessUnits :checkbox:checked').length) > 5)
{
alert("Max 5 BU's can be selected");
//is it possible to uncheck here? I am unable to find any method to do so.
}
}
}
C#是如下:
protected void ckBLBusinessUnits_SelectedIndexChanged(object sender, EventArgs e)
{
if (selectedValues.Count <= 5)
{
//Do something and then disable the loader.
loadingImage.Style.Add("display", "none");
}
else if (selectedValues.Count > 5)
{
//is it possible to uncheck here? I am unable to find any method to do so.
}
}