我將一個數據集綁定到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 –