簡體   English   中英

在TabContainer中隱藏和顯示TabPanel

[英]Hide and Display of TabPanel in TabContainer

我試圖在應用程序啟動時隱藏TabPanel4 ,然后當用戶從下拉列表中選擇特定項目時,它會為用戶顯示TabPanel4 下面是我使用的代碼,不確定為什么不起作用。 幫我看看我的代碼,看看我做錯了什么部分。 謝謝!

Aspx

<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>&nbsp;<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;
    }
}

補充說明:即使我從aspx頁面上刪除了Visible="false"並將其設置在Page_Load下的頁面后面的代碼中,它也不起作用,當我在下拉列表中選擇該項時,它仍然不會出現。 還嘗試使用TabContainer1.Tabs[3].Visible = false / true; 隱藏或顯示它,但它似乎也不起作用。

ddlToC不處理SelectedIndexChanged

將您的標記更改為此:

<asp:DropDownList ID="ddlToC" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlToC_SelectedIndexChanged">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM