我试图隐藏TabPanel4
应用程序何时启动,然后当用户从下拉列表中选择特定项目时,它会TabPanel4
为用户显示出来。下面是我使用的代码,不知道为什么它不起作用。请帮我看看我的代码,看看我做错了哪一部分。谢谢!
象素
<asp:TabContainer ID="TabContainer1" runat="server" Height="75%" Width="100%" UseHorizontalStripPlacement="true"
ActiveTabIndex="0" OnDemand="true" AutoPostBack="true" TabStripPlacement="Top" ScrollBars="Auto">
<asp:TabPanel ID="TabPanel1" runat="server" HeaderText="Incident Information" Enabled="true" ScrollBars="Auto" OnDemandMode="Once">
<ContentTemplate>
<table width="100%">
<tr>
<td>
<b>Type of crime:</b>
<asp:DropDownList ID="ddlToC" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlToC_SelectedIndexChanged">
<asp:ListItem>Accident</asp:ListItem>
<asp:ListItem>Theft</asp:ListItem>
<asp:ListItem>Robbery</asp:ListItem>
<asp:ListItem>Housebreaking</asp:ListItem>
<asp:ListItem>Fraud</asp:ListItem>
<asp:ListItem>Loan Shark</asp:ListItem>
</asp:DropDownList>
<br />
</td>
</tr>
</table>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel4" runat="server" HeaderText="Property" Enabled="true" ScrollBars="Auto" OnDemandMode="Once" Visible="false">
<ContentTemplate>
Is there any property lost in the incident?
<asp:RadioButton ID="rbPropertyYes" runat="server" GroupName="rbGroup3" Text="Yes" AutoPostBack="True" />
<asp:RadioButton ID="rbPropertyNo" runat="server" GroupName="rbGroup3" Text="No" AutoPostBack="True" />
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Describe what was lost in the incident." Visible="False"></asp:Label>
<br />
<br />
<asp:TextBox ID="txtProperty" runat="server" Height="75px" TextWrapping="Wrap" TextMode="MultiLine" Width="400px" Visible="False"/>
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="You have " Visible="False"></asp:Label><asp:Label ID="lblCount3" runat="server" Text="500" Visible="False"></asp:Label> <asp:Label ID="Label6" runat="server" Text=" characters left." Visible="False"></asp:Label>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
背后的代码
protected void ddlToC_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlToC.SelectedValue.Equals("Theft"))
{
TabPanel4.Visible = true;
}
else if (ddlToC.SelectedValue.Equals("Robbery"))
{
TabPanel4.Visible = true;
}
else if (ddlToC.SelectedValue.Equals("Housebreaking"))
{
TabPanel4.Visible = true;
}
else if (ddlToC.SelectedValue.Equals("Fraud"))
{
TabPanel4.Visible = true;
}
}
补充一点:即使我Visible="false"
从aspx页面中取出并将其设置在页面后面的代码中Page_Load
也不起作用,当我在下拉列表中选择项目时它仍然不会出现。还尝试使用TabContainer1.Tabs[3].Visible = false / true;
隐藏或显示它,但它似乎也不起作用。