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.
}
}