2013-10-13 56 views
0

我從Toolbox添加了DropDownList到我正在處理的網站上的登錄頁面。ASP.NET與DropDownList

一旦我選擇在DropDownList一個ListItem(在我的情況可以說 健身房例如...),點擊後,我想這三個酒吧我們將在下面我DropDownList(例如,在酒吧被打開的我們將打開用戶名,密碼和ID),我的意思是三個文本框在對方下面。

http://imageshack.us/photo/my-images/854/w7wn.jpg

回答

0

我認爲你可以嘗試SelectedIndexChanged事件或JavaScript沒有回傳,以顯示文本框。

0
<select> 
<option value="1">Gym 1</option> 
<option value="2">Gym 2</option> 
<option value="3">Gym 3</option> 
<select> 
0

在firest你把你的文本框在一個panle則隱藏此面板和 你drobdownlist爲真,並選擇在DropDownList的一個項目後,你應該設置AutoPostBack屬性,回傳會ACCUR。所以你可以顯示該面板包含文本框。

0

你可能真正需要的是動態文本框。

在HTML的一部分:

<asp:DropDownList runat="server" ID="DDL1" autopostback = "true" onselectedindexchanged="DDL_SelectChanged" /> <asp:PlaceHolder runat="server" ID="PH1"> </asp:PlaceHolder>

在代碼隱藏:

void DDL_SelectChanged(object sender, EventArgs e) 
    { 
     if (DDL1.SelectedIndex == 1) 
     { 
      for (int i = 0; i < 3; i++) 
      { 
       TextBox newTB = new TextBox(); 
       newTB.ID = "TB" + i; 
       PH1.Controls.Add(newTB); 
      } 
     } 
    } 
0

你可以使用MultiveView控制。並在Dropdown的selectedIndexChanged事件中設置活動視圖索引。 我寫了一些示例代碼爲您提供:

ASPX方:

<asp:MultiView ID="multiView" ActiveViewIndex="-1" runat="server"> 
     <asp:View ID="viewGym" runat="server"> 
      <asp:TextBox ID="txtBxUserName" runat="server" /> 
      <asp:TextBox ID="txtBxPassword" runat="server" /> 
      <asp:TextBox ID="txtBxId" runat="server" /> 
     </asp:View> 
    </asp:MultiView> 
    <asp:DropDownList ID="Dropdownlist1" runat="server" AutoPostBack="true" 
     onselectedindexchanged="Dropdownlist1_SelectedIndexChanged"> 
     <asp:ListItem Text="Choose one club" Value="0" /> 
     <asp:ListItem Text="Gym" Value="1" /> 
     <asp:ListItem Text="Shoppers" Value="2" /> 
    </asp:DropDownList> 

代碼背後:

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (IsPostBack) //don't forget :) 
      return; 
    } 

    protected void Dropdownlist1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     if (Dropdownlist1.SelectedValue == "1") //Gym item selected 
     { 
      multiView.ActiveViewIndex = 0; //Gym view active 
     } 
    } 

如果你想任何觀點不活躍時,首先頁面加載,然後您在aspx代碼中將-1設置爲ActiveViewIndex。