我将一个数据集绑定到VB.net中的GridView。我有一些自定义的排序设置,并且如果选择了我的3个选项之一,则希望在标题旁边显示一个图标。带排序图标的Gridview标题
我已经阅读了很多这样做的方法,我看到Gridviews甚至有一个ASC和DESC标题样式可以与视图关联。我有这个问题,但2:
- 我排序列表与linq排序触发器,然后绑定到数据网格。
- 我之所以做这种方式,就是我要维护多个排序级别,由3列排序,而不是1
编辑为清楚起见 具体是什么我想要做的是遍历GridView的Header文本的值,看看它是否与我在viewstate中保存的内容相匹配,如果是,则特别为该头添加图像。本质的东西像下面,但headerRow.Cells(Y)。文本总是返回“”,即使头有文字:
Sub gvPatronData_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim savedSortDirection(), savedSortColumn() As String
Dim headerRow As GridViewRow = gvPatronData.HeaderRow
'this sets the values of these variables
'as strings equal to the text displayed in the header of the gridview
_patronBl.SplitPatronSort(savedSortDirection, SortDirection, savedSortColumn, SortColumn)
If SortDirection <> "" Then
If e.Row.RowType = DataControlRowType.Header Then
For x = 0 To savedSortDirection.Length - 1
For y = 0 To headerRow.Cells.Count - 1
If headerRow.Cells(y).Text = savedSortColumn(x) Then
If savedSortDirection(x) = "Ascending" Then
Dim bGStyle As New System.Web.UI.WebControls.Style()
bGStyle.CssClass = "upSort"
headerRow.Cells(y).ApplyStyle(bGStyle)
Else
Dim bGStyle As New System.Web.UI.WebControls.Style()
bGStyle.CssClass = "downSort"
headerRow.Cells(y).ApplyStyle(bGStyle)
End If
End If
Next
Next
End If
End If
End Sub
我想弄清楚,你所谈论的ASP.NET的GridView和不WinForm的的DataGridView的,不是吗? –
是的,ASP .NET的GridView。 –
你的实际问题是什么,你试过甚么?下面是一个简单的例子:http://www.codeproject.com/KB/aspnet/Gridview_Sorting_Paging.aspx –