2012-03-13 60 views
0

我做了一個表單發送到我的電子郵件。 現在有一個下拉列表框,其中有一個選項afew,可以說顏色,最後有選項「其他」,我想要一個文本框apear beanth所以客戶端可以寫「顏色」他想。asp.net vb如何在按下時打開一個文本框

anyidea如何使它?

進出口使用VBcode與ASP.NET

,如果你需要我的代碼,請讓我知道

預先感謝您

回答

0

您可以設置AutoPostBack=True,然後處理OnSelectedIndexChanged事件。在事件處理程序中檢查DropdownList.SelectedItem.Text =「其他」,然後顯示或隱藏文本框。

使用更新面板避免整頁回發。

<asp:DropDownList ID="DropDownList1" runat="server" 
     onselectedindexchanged="DL1_SelectedIndexChanged" AutoPostBack="true"> 
     <asp:ListItem></asp:ListItem> 
     <asp:ListItem>Others</asp:ListItem> 
    </asp:DropDownList> 
    <asp:TextBox ID="TextBox1" runat="server" Visible="false"> 

而在代碼隱藏

Protected Sub DL1_SelectedIndexChanged(sender As Object, e As EventArgs) 
    If DropDownList1.SelectedItem.Text = "Others" Then 
     TextBox1.Visible = True 
     Else 
       TextBox1.Visible= False 
    End If 
End Sub 
+0

你能給我一個完整的代碼的例子嗎? – pelleg 2012-03-13 12:18:57

+0

更新了代碼。 – PraveenVenu 2012-03-13 12:40:40

+0

我把代碼放在上面。但是當我選擇別人 – pelleg 2012-03-13 13:29:10

0

編輯:

這裏是你的DropDownList。設置在開始的Visible屬性設置爲false爲您TextBox控件

 <asp:DropDownList ID="DropDownList1" runat="server" 
     onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack=true> 
     <asp:ListItem></asp:ListItem> 
     <asp:ListItem>Other</asp:ListItem> 
    </asp:DropDownList> 

C#代碼對不起我是壞在VB BT其簡單。希望你會明白的。

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     if (DropDownList1.SelectedItem.ToString() == "Other") 
     { 
      TextBox1.Visible = true; 
     } 
    } 
相關問題