2008-11-21 62 views
1

我有如下表添加动态面板/控制

<td class="style2"> 
    <asp:DropDownList ID="DropDownList1" runat="server"> 
     <asp:ListItem>Location</asp:ListItem> 
     <asp:ListItem>Name</asp:ListItem> 
     <asp:ListItem>SSN</asp:ListItem> 
    </asp:DropDownList> 
    <asp:DropDownList ID="DropDownList2" runat="server"> 
     <asp:ListItem>LIKE</asp:ListItem> 
     <asp:ListItem>=</asp:ListItem> 
    </asp:DropDownList> 
    <br /> 
    <br /> 
</td> 
<td valign="bottom"> 
    <asp:Button ID="btnAdd" runat="server" Text="Add" /> 
</td> 

当btnAdd点击我要添加这些过滤器的另一行。我假设我将创建一个面板并拥有这3个控件,添加按钮将创建一个新面板,或者创建所有控件,然后添加代码。

编辑:: 当我btnAdd单击,然后我想补充另一行这样

btnAdd之前点击

<td class="style2"> 
     <asp:DropDownList ID="DropDownList1" runat="server"> 
      <asp:ListItem>Location</asp:ListItem> 
      <asp:ListItem>Name</asp:ListItem> 
      <asp:ListItem>SSN</asp:ListItem> 
     </asp:DropDownList> 
     <asp:DropDownList ID="DropDownList2" runat="server"> 
      <asp:ListItem>LIKE</asp:ListItem> 
      <asp:ListItem>=</asp:ListItem> 
     </asp:DropDownList> 
     <br /> 
     <br /> 

    </td> 

btnAdd后:

<td class="style2"> 
     <asp:DropDownList ID="DropDownList1" runat="server"> 
      <asp:ListItem>Location</asp:ListItem> 
      <asp:ListItem>Name</asp:ListItem> 
      <asp:ListItem>SSN</asp:ListItem> 
     </asp:DropDownList> 
     <asp:DropDownList ID="DropDownList2" runat="server"> 
      <asp:ListItem>LIKE</asp:ListItem> 
      <asp:ListItem>=</asp:ListItem> 
     </asp:DropDownList> 
     <br /> 
     <br /> 
    </td> 

<tr> 
<td class="style2"> 
     <asp:DropDownList ID="DropDownList1" runat="server"> 
      <asp:ListItem>Location</asp:ListItem> 
      <asp:ListItem>Name</asp:ListItem> 
      <asp:ListItem>SSN</asp:ListItem> 
     </asp:DropDownList> 
     <asp:DropDownList ID="DropDownList2" runat="server"> 
      <asp:ListItem>LIKE</asp:ListItem> 
      <asp:ListItem>=</asp:ListItem> 
     </asp:DropDownList> 
     <br /> 
     <br /> 
    </td> 
</tr> 

回答

0

它会更容易显示/隐藏第三个下拉列表,而不是动态添加它。

DropDownList3.Visible = true; 

当你动态地添加你进入的视图状态的问题,如果你没有在正确的时间(页面生命周期)添加它,它不值得冒这个险,如果你能避免它。

如果你必须那么我会让你的行进入用户控件,并不断添加新的实例。重新加载视图状态发生在初始化和加载后,所以确保你的控件在init中加载,理想情况下在所有回传中。

+0

Trull:我编辑了我的问题 – user38230 2008-11-21 14:02:38

0

你可以在后面的代码中做一些事情,让你的下拉菜单可见。换句话说:

<td class="style2"> 
    <asp:DropDownList ID="DropDownList3" runat="server" Visible="false"> 
     <asp:ListItem>Location</asp:ListItem> 
     <asp:ListItem>Name</asp:ListItem> 
     <asp:ListItem>SSN</asp:ListItem> 
    </asp:DropDownList> 
    <asp:DropDownList ID="DropDownList4" runat="server" Visible="false"> 
     <asp:ListItem>LIKE</asp:ListItem> 
     <asp:ListItem>=</asp:ListItem> 
    </asp:DropDownList> 

而后面的代码就会有这个在button_OnClick事件:

DropDownList3.Visible = true; 
DropDownList4.Visilbe = true; 

当然,如果你在一个UpdatePanel做这些,就会使过渡比刷新更好整个页面。

+0

GregD:我编辑了我的问题 – user38230 2008-11-21 14:01:45