我有一个包含两个字段和两个列表视图的下拉列表,具体取决于我从下拉列表中选择的选项,两个列表视图之一必须隐藏
<div class="dropdown">
<asp:DropDownList ID="DropDownList1" CssClass="btn btn-primary" runat="server" AutoPostBack="True" BackColor="#3B5998" DataTextField="DenominazioneTipo" DataValueField="IdTipo" DataSourceID="SqlDataSource4" >
</asp:DropDownList>
</div>
<br />
<div>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:dbConnection %>" SelectCommand="SELECT * FROM [Tipocliente]"></asp:SqlDataSource>
答案 0 :(得分:1)
尝试OnSelectedIndexChanged
,然后根据索引或所选值可以显示和隐藏
在.aspx中
<asp:DropDownList ID="DropDownList1" CssClass="btn btn-primary" runat="server" AutoPostBack="True" BackColor="#3B5998" DataTextField="DenominazioneTipo" DataValueField="IdTipo" DataSourceID="SqlDataSource4" OnSelectedIndexChanged = "DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
在.aspx.cs中
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if(DropDownList1.SelectedIndex == 0)
{
ListView1.Visible = true;
ListView2.Visible = false;
}
else if(DropDownList1.SelectedIndex == 1)
{
ListView1.Visible = false;
ListView2.Visible = true;
}
}