2013-03-17 33 views
1

C#代碼:顯示隱藏的文本框,標籤下拉列表的selectedIndex後改變

protected void DropDownListDB_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     if (DropDownListDB.SelectedValue == "Other") 
     { 
      LabelIfOtherDb.Visible = true; 
      TextBoxIfOtherDb.Visible = true; 
     } 
    } 

ASP代碼:

   <asp:DropDownList AutoPostBack="True" ID="DropDownListDB" runat="server" Height="20px" 
        Width="158px"> 
        <asp:ListItem>- Select -</asp:ListItem> 
        <asp:ListItem>Oracle</asp:ListItem> 
        <asp:ListItem>MS SQL Server</asp:ListItem> 
        <asp:ListItem>MySQL</asp:ListItem> 
        <asp:ListItem>MS Access</asp:ListItem> 
        <asp:ListItem>Other</asp:ListItem> 
       </asp:DropDownList> 

我有AutoPostBack="True"但仍沒有顯示我的隱藏文本/標籤。任何建議?

回答

4

看來,你的事件沒有連接到事件處理程序。 兩種可能性:要麼,定義事件處理程序的標記,如:

<asp:DropDownList AutoPostBack="True" ID="DropDownListDB" runat="server" Height="20px" SelectedIndexChanged="DropDownListDB_SelectedIndexChanged"> 

或代碼隱藏

DropDownListDB.SelectedIndexChanged += DrowpDownListDB_SelectedIndexChanged; 

你應該加價,雖然把這個了。

+0

奇怪..我雙擊我的下拉列表,然後它會自動創建事件處理程序非常相同的問題..真的很奇怪呵呵,這是解決ofcourse .. 謝謝!新手失敗;)hehe – Kriistiian 2013-03-17 20:44:47

+0

不客氣。請標記爲答案。 – 2013-03-17 20:45:46

0

這個作品有一個大學分配

<asp:DropDownList ID="DropDownList1" AutoPostBack="true" 
    runat="server" Height="16px" Width="237px" 
    onselectedindexchanged="DropDownList1_SelectedIndexChanged"/> 
+0

請檢查一下前面已經存在的答案,表示與您的答案几乎完全相同。 – 2013-05-02 09:05:58

相關問題