【发布时间】:2011-09-02 17:11:59
【问题描述】:
我希望动态更改 ListView 的 ItemTemplate 中的列数:
<asp:ListView runat="server" ID="ReportListView" DataSourceID="ReportListViewSDS">
<LayoutTemplate>
<table>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" />
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<!-- need to dynamically create the number of columns in the code behind
based on the select statement in the SelectCommand -->
</ItemTemplate>
</asp:ListView>
然后在后面的代码中我得到了:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Based on The Request.Form variables sent, the SQL command will
' select x number of columns:
' SqlStatement = "SELECT " for each Request.Form values " FROM staff"
' example: "SELECT Fname, Lname, email, phone FROM staff"
' Run sql command.
' that all works, the question now is how do i change the ItemTemplate
' so that it has the correct number of columns. Something like this: (pseudo code)
For each row found in sql command
ReportListView.ItemTemplate.Add( "<tr>" )
For each Request.Form as i
ReportLIstView.ItemTemplate.Add( "<td>" & sqlresult(i) & "</td>" )
Next
ReportListView.ItemTemplate.Add( "</tr>" )
Next
End Sub
也许还有另一种方法可以解决,但这是迄今为止唯一的想法。 asp.net新手,任何建议,非常欢迎!谢谢!
【问题讨论】:
标签: asp.net vb.net listview itemtemplate