2011-09-06 37 views
1

由于服务器上的环境限制,仅限于使用.Net框架的v2.0(我们使用VB.net)。如何显示具有单个对象和子列表(对象)的列表(对象)?

我有一个ASP.net网页,它从一个web服务中提取数据,对活动目录中的用户帐户执行检查。操作员可以使用Web界面一次检查多个帐户。 webservice返回一个(AccountCheck)对象列表,它们本身包含单个属性,如用户名,电子邮件地址和包含多个属性的List(AccountError)对象。

所以账户确认的物体看起来像这样:

Username 
FriendlyName 
Email 
AccountError1 > Message > Weight > ResolverTeam > etc 
AccountError2 > Message > Weight > ResolverTeam > etc 
AccountError3 > Message > Weight > ResolverTeam > etc 
AccountError4 > Message > Weight > ResolverTeam > etc 
AccountError5 > Message > Weight > ResolverTeam > etc 

Username 
FriendlyName 
Email 
AccountError1 > Message > Weight > ResolverTeam > etc 
AccountError2 > Message > Weight > ResolverTeam > etc 
AccountError3 > Message > Weight > ResolverTeam > etc 
AccountError4 > Message > Weight > ResolverTeam > etc 
AccountError5 > Message > Weight > ResolverTeam > etc 

Username 
FriendlyName 
Email 
AccountError1 > Message > Weight > ResolverTeam > etc 
AccountError2 > Message > Weight > ResolverTeam > etc 
AccountError3 > Message > Weight > ResolverTeam > etc 
AccountError4 > Message > Weight > ResolverTeam > etc 
AccountError5 > Message > Weight > ResolverTeam > etc 

我要的是使用某种中继做,创建多个面板或含有标签显示的用户名的div,电子邮件等等,以及一个gridview,它有一个accounterror列表绑定到它来显示所有的错误。用户可以一次检查2,5,7个账户,并且是动态的。

这是什么最好的方法呢?

+0

中继器嵌套中继器的错误信息 – sll

回答

1

您将需要嵌套两个列表控件;例如,中继器和网格视图,或中继器和中继器,具体取决于您在布局上需要多少控制。相关部分是将数据绑定内部控制与内部列表中的数据源:

<asp:Repeater ...> 
    <ItemTemplate> 
     <%# Eval("Username") %> 
     ... 
     <asp:GridView DataSource='<%# Eval("AccountErrors") %>' ...> 
      ... 
     </asp:GridView> 
    </ItemTemplate> 
</asp:Repeater> 
+0

我得到的错误“服务器标记不能包含<% ... %>结构”采用t他的方法。虽然看起来不错,但很简单。 –

+0

@Tom Pickles:你确定你在'<%'后面有'#'吗? – Heinzi

+1

这工作:DataSource ='<%#DataBinder.Eval(Container.DataItem,“AccountErrors”)%>'。谢谢你的帮助。 –

1

您可以使用一个DataList尝试是这样的:

<table width="595px"> 
    <asp:DataList BackColor="#ffffff" id="DataList1" DataKeyField="<ID>" OnItemDataBound="DataList1_ItemDataBound" runat="server" Width="100%">  
     <ItemTemplate> 
      <tr> 
       <td> 
        <asp:LinkButton ID="LinkButton1" runat="server" Text="+" OnCommand="LinkButton1_Command" CommandArgument='<%#Container.ItemIndex%>'></asp:LinkButton>  
       </td> 
       <td><%#Eval("<COLUMN NAME>")%></td> 
       <td><%#Eval("<COLUMN NAME>")%></td> 
       <td><%#Eval("<COLUMN NAME>")%></td> 
      </tr> 
      <asp:Panel ID="pnlChildView" runat="server"> 
       <asp:DataList ID="DataList2" runat="server" Width="100%"> 
        <ItemTemplate> 
         <tr> 
          <td><%#Eval("<CHILD OLUMN NAME>")%></td> 
          <td><%#Eval("<CHILD COLUMN NAME>")%></</td> 
          <td><%#Eval("<CHILD COLUMN NAME>")%></</td>        
         </tr> 
        </ItemTemplate> 
       </asp:DataList> 
      </asp:Panel> 
     </ItemTemplate> 
    </asp:DataList> 
</table> 

而当用户点击LinkBut​​ton的/按钮DataList1,做这样的事情:

protected void LinkButton1_Command(object sender, CommandEventArgs e) 
{ 
    //pass index of item in command argument 
    int itemIndex = Convert.ToInt32(e.CommandArgument);  

    //find the pnlChildView control 
    Panel childViewPanel = (Panel)DataList1.Items[itemIndex].FindControl("pnlChildView"); 
    if (childViewPanel != null) 
    { 
     //toggle visibility of childViewPanel and bind child list if panel is visible 

     if (childViewPanel.Visible) 
     { 
      DataList childList = childViewPanel.FindControl("DataList2"); 
      if (childList != null) 
      { 
       int keyValue = (int)DataList1.DataKeys[itemIndex]; 

       //bind the list using DataList1 data key value 
       childList.DataSource = <DATA SOURCE>; //get data using keyValue 
       childList.DataBind(); 
      } 
     } 
    } 
} 
相关问题