我有一个下拉菜单,它有一组项目。我想在点击下拉菜单时隐藏特定的面板。
下面是我的c#代码,我的面板是在asp.net中设计的。
当我点击面板XII
中的下拉列表项Not Applicable
X
protected void ddsscboard_SelectedIndexChanged(object sender, EventArgs e)
{
try {
string sscpanel = ddsscboard.SelectedItem.Text;
panelshow(sscpanel);
}
catch(Exception ex)
{
}
}
public void panelshow(string sscpanel)
{
if (sscpanel == "Not Applicable")
XII.Visible = false;
else
lblmsg.Text = sscpanel;
}
}
面板: -
X级
<div class="form-group">
<label>Select Board</label>
<asp:DropDownList ID="ddsscboard" CssClass="form-control" OnSelectedIndexChanged="ddsscboard_SelectedIndexChanged" runat="server">
<asp:ListItem>Not Applicable</asp:ListItem>
<asp:ListItem>SSC</asp:ListItem>
<asp:ListItem>CBSC</asp:ListItem>
<asp:ListItem>ICSC</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
</div>
<div class="form-group">
<label>Complition Month</label>
<asp:TextBox ID="txtssccomplitionmonth" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Complition Year</label>
<asp:TextBox ID="txtssccomplitionyear" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Marks Obtained</label>
<asp:TextBox ID="txtsscmarksobtained" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Total Marks</label>
<asp:TextBox ID="txtssctotalmarks" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Upload File</label>
<asp:FileUpload ID="sscfile" runat="server" />
</div>
</div>
<!-- /.col-lg-6 (nested) -->
</div>
<!-- /.row (nested) -->
</div>
</asp:Panel>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<div class="col-lg-12">
<asp:Panel ID="XII" runat="server" CssClass="panel panel-default">
<div class="panel-heading">
Class XII
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>Select Board</label>
<asp:DropDownList ID="ddhscboard" CssClass="form-control" runat="server">
<asp:ListItem>Not Applicable</asp:ListItem>
<asp:ListItem>HSC</asp:ListItem>
<asp:ListItem>CBSC</asp:ListItem>
<asp:ListItem>ICSC</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
</div>
<div class="form-group">
<label>Complition Month</label>
<asp:TextBox ID="txthsccomplitionmonth" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Complition Year</label>
<asp:TextBox ID="txthsccomplitionyear" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Marks Obtained</label>
<asp:TextBox ID="txthscmarksobtained" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Total Marks</label>
<asp:TextBox ID="txthsctotalmarks" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Upload File</label>
<asp:FileUpload ID="hscfile" runat="server" />
</div>
</div>
<!-- /.col-lg-6 (nested) -->
</div>
<!-- /.row (nested) -->
</div>
</asp:Panel>
<!-- /.panel-body -->
</div>
答案 0 :(得分:0)
您需要将DropDownList中的AutoPostBack属性设置为true。请注意,您可能还需要建立一个空白ListItem,因此默认情况下不选择“Not Applicable”:
<asp:DropDownList AutoPostBack="true" ID="ddsscboard" CssClass="form-control" OnSelectedIndexChanged="ddsscboard_SelectedIndexChanged" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Not Applicable</asp:ListItem>
<asp:ListItem>SSC</asp:ListItem>
<asp:ListItem>CBSC</asp:ListItem>
<asp:ListItem>ICSC</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>