2011-07-21 31 views
2

的ListView Web控制問題:的ListView Asp.Net控制 - 分配字符串列表視圖的列

我開發使用Asp.Net 3.5和ReportingService2010.asmx報告服務Web應用程序。我檢索到的ItemHistorySnapshots用下面的代碼:

ItemHistorySnapshot[] itemSnapshots = null; 
itemSnapshots = rs.ListItemHistory(strChildNode); 

foreach(ItemHistorySnapshot snapshot in itemSnapshots) { 
    listview.add (snapshot.HistoryID.Tostring()); 
    listview.add (snapshot.Size.Tostring()); 
    listview.add(snapshot.DateTime.Tostring()); 
} 

我想創建一個ListView 3列HistoryID,大小,日期時間,想在foreach循環分配的字符串值。

請讓我知道如何將字符串值分配給ListView。我也想知道listview的源代碼控制代碼。非常感謝你。

回答

0

您可以使用中繼器和數據綁定到它,就像這樣:

後面的代碼:

ItemHistorySnapshot[] itemSnapshots = null; 
itemSnapshots = rs.ListItemHistory(strChildNode); 

rpt.DataSource = itemSnapshots.Select(s => new 
{ 
    HistoryID = s.HistoryID.ToString(), 
    Size = s.Size.ToString(), 
    DateTime = s.DateTime.ToString(), 
}); 
rpt.DataBind(); 

ASPX頁面:

<asp:Repeater id="rpt" runat="server"> 

    <HeaderTemplate> 
    <table border="1" width="100%"> 
     <tr> 
      <th>HistoryID</th> 
      <th>Size</th> 
      <th>DateTime</th> 
     </tr> 
    </HeaderTemplate> 

    <ItemTemplate> 
    <tr> 
     <td><%# Eval("HistoryID") %></td> 
     <td><%# Eval("Size") %></td> 
     <td><%# Eval("DateTime") %></td> 
    </tr> 
    </ItemTemplate> 

    <FooterTemplate> 
    </table> 
    </FooterTemplate> 

</asp:Repeater> 
相關問題