选择第二个列表项后。第3个下拉列表的“选择类别...”不再被禁用,它变得可点击/可选择。
“选择类别...”应在所有下拉列表中保持禁用状态。
我认为它与Autopostback和UpdatePanel有关。 因为我使用updatepanel在回发时保持模态打开,我使用Autopostback从下拉列表中删除所选项目。
这是我的代码:
<form class="form-horizontal" runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal-body">
<div class="form-group">
<div class="col-lg-10">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<asp:DropDownList ID="ddl1" runat="server" class="form-control" MaxLength="50" OnSelectedIndexChanged="ddl1_SelectedIndexChanged" AutoPostBack="true" required >
<asp:ListItem Value="" disabled="disabled">Select Category...</asp:ListItem>
<asp:ListItem>Artist/Curator</asp:ListItem>
<asp:ListItem>MCAD Exhibitor</asp:ListItem>
<asp:ListItem>Student</asp:ListItem>
<asp:ListItem>Collector/Buyer</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-10">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<asp:DropDownList ID="ddl2" runat="server" class="form-control" MaxLength="50" OnSelectedIndexChanged="ddl2_SelectedIndexChanged" AutoPostBack="true" required >
<asp:ListItem Value="" disabled="disabled">Select Category...</asp:ListItem>
<asp:ListItem>Artist/Curator</asp:ListItem>
<asp:ListItem>MCAD Exhibitor</asp:ListItem>
<asp:ListItem>Student</asp:ListItem>
<asp:ListItem>Collector/Buyer</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-10">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<asp:DropDownList ID="ddl3" runat="server" class="form-control" MaxLength="50" OnSelectedIndexChanged="ddl3_SelectedIndexChanged" AutoPostBack="true" required >
<asp:ListItem Value="" disabled="disabled">Select Category...</asp:ListItem>
<asp:ListItem>Artist/Curator</asp:ListItem>
<asp:ListItem>MCAD Exhibitor</asp:ListItem>
<asp:ListItem>Student</asp:ListItem>
<asp:ListItem>Collector/Buyer</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
我的代码.cs:
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
ddl2.Items.Remove(ddl1.SelectedItem);
ddl3.Items.Remove(ddl1.SelectedItem);
UpdatePanel1.Update();
}
protected void ddl2_SelectedIndexChanged(object sender, EventArgs e)
{
ddl1.Items.Remove(ddl2.SelectedItem);
ddl3.Items.Remove(ddl2.SelectedItem);
UpdatePanel1.Update();
}
protected void ddl3_SelectedIndexChanged(object sender, EventArgs e)
{
ddl1.Items.Remove(ddl3.SelectedItem);
ddl2.Items.Remove(ddl3.SelectedItem);
UpdatePanel1.Update();
}
答案 0 :(得分:0)
这不是关于您的更新面板(我测试过)。我认为这是一个下拉列表的不良行为(或错误),当您删除其项目时,它选择其第一项并删除该残疾。要解决此问题,您可以轻松地将此jquery添加到代码的末尾:
$('select').each(function ()
{
$(this).children().eq(0).attr('disabled', 'disabled');
});
如果您不想使用jquery,请在下拉后粘贴此脚本:
<script>
var arr = document.getElementsByClassName('form-control');
for (var i = 0; i < arr.length; i++)
{
console.log(arr[i]);
arr[i].children[0].setAttribute('disabled', 'disabled');
}
</script>