我希望下拉列表自动启用一旦当前一个被选中,我写了代码来实现这一点,但没有在页面上的响应。
该代码用于用户从下拉列表中选择多个课程
HTML标记:
<asp:DropDownList ID="DropDownList4" class="form-control form-control-lg" runat="server" AutoPostBack="True" OnSelectedIndexChanged="List_Change"></asp:DropDownList>
<asp:DropDownList ID="DropDownList5" class="form-control form-control-lg" Enabled="false" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList6" class="form-control form-control-lg" Visible="false" AutoPostBack="True" Enabled="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList7" class="form-control form-control-lg" Enabled="false" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList8" class="form-control form-control-lg" Enabled="false" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList9" class="form-control form-control-lg" Enabled="false" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList10" class="form-control form-control-lg" Enabled="false" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList11" class="form-control form-control-lg" Enabled="false" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList12" class="form-control form-control-lg" Enabled="false" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList13" class="form-control form-control-lg" Enabled="false" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList14" class="form-control form-control-lg" Enabled="false" AutoPostBack="True" Visible="false" OnSelectedIndexChanged="List_Change" runat="server"></asp:DropDownList>
字符串
C#代码:
static int i = 4;
protected void List_Change(object sender, EventArgs e)
{
DropDownList ddlid form1.FindControl("DropDownList" + i) as DropDownList;
while (i <= 14)
{
if (ddlid.Enabled && ddlid.Text != "--Select Course--")
{
++i;
ddlid.Enabled = true;
ddlid.Visible = true;
}
else
{
break;
}
}
}
型
页面加载正常,没有任何错误,但一旦我在DropDownList4
上选择了课程,就没有响应
1条答案
按热度按时间q35jwt9p1#
逻辑不正确;不需要使用静态变量,循环也是不必要的,最后主要原因是下一个if块总是检查当前下拉列表。
只需检查下一个下拉列表,而不是所有下拉列表:
字符串