我有一个复选框页面,我选择它们中的一些,单击submit,然后转到第二页。在这个页面上,我有一个使用前一页选择的复选框构建的列表视图。现在我想知道如何为此列表视图添加排序功能。当它不包含layouttemplate并且内置代码隐藏时,使listview可排序
在过去,我会将CommandName ='sort'CommandArgument ='column'添加到LayoutTemplate中标题的链接上。但是由于我的listview在列表视图之外有它的标题行,所以这似乎不起作用。关于如何实现这一点的任何想法?这是我到目前为止有:
<!-- header row (outside of listview, when I try to put it as a LayoutTemplate in listview i get an error, see below) -->
<table>
<tr><% For Each i As String In Request.Form
If i.IndexOf("checkbox_") = 0 Then
Response.Write("<th>" & i.Substring(Len("checkbox_")) & "</th>")
End If
Next %></tr>
</table>
<!-- Then the listview: -->
<asp:ListView runat="server" ID="ReportListView" DataSourceID="ReportListViewSDS">
<ItemTemplate>
<table>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" />
</tr>
</table>
</ItemTemplate>
</asp:ListView>
在后面的代码
然后:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' This works fine:
' Get the Request Vars that are checkboxes, and build the sql command.
' Run the sql command
' Databind()
End Sub
' while binding the data, build the itemPlaceholder, to contain the contents of what's returned in the sql:
Protected Sub ReportListView_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ReportListView.ItemDataBound
If (e.Item.ItemType = ListViewItemType.DataItem) Then
Dim plc As PlaceHolder = DirectCast(e.Item.FindControl("itemPlaceHolder"), PlaceHolder)
Dim di As Data.DataRowView = e.Item.DataItem()
For Each c In di.Row.ItemArray
Dim l As New Literal
l.Text = String.Format("<td class='customreport'>{0}</td>", c.ToString)
plc.Controls.Add(l)
Next
End If
End Sub
我一直在努力,在列表视图中添加templatelayout,但给我就行了一个错误,绑定数据(listview.databind()),我假设,因为这是不可能的。
任何方式来获得这个列表视图上的可排序标题行?提前致谢?新手,对不起。
是的,我确实尝试过,但没有得到它的工作。你可能有一个工作的例子,或更多的细节?我检查了这些页面,并试图准确地执行代码。问题是当我点击应该排序的链接按钮时,页面只刷新,排序不适用。有任何想法吗?谢谢! – russds
我认为问题在于Linkbuttons不在Listview中。因为我添加了“CommandName”=排序到listview之外的链接按钮,这可能就是为什么它们没有任何效果。再一次,它回到没有LayoutTemplate。因为我刚刚在列表视图之外创建了一个表来充当我的表头。 – russds