日期:2014-05-18  浏览次数:20512 次

急求:如何在GridView的排序时显示“向上”“向下”箭头的图片。在线。[100分]
就是这种效果
-------------------------------
学号|姓名|数学成绩 ↑|语言成绩 ↓
-------------------------------
1         |小王   |   98                     |     60
----------------------------
2         |小刘   |   80                     |     90
-------------------------


当点击GridView列名时,会引发排序的,但不知道如何在列名上加一个指上指下的箭头(图片)。请高手说说,如何给列名上加图片呢

------解决方案--------------------
Private Shared SortStr, SortDirection As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
Try
binddata() '你的code
Catch ex As Exception
Response.Redirect( "Error.aspx ")
End Try

SortStr = "UserID " 'your key
SortDirection = " Asc "
End If
End Sub
Private Sub binddata()
Dim MyView As DataView
MyView = ' ' ' ' 'your dataview
MyView.Sort = SortStr & SortDirection
dagUsers.DataSource = MyView
dagUsers.DataBind()
End Sub

Private Sub dagUsers_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dagUsers.SortCommand 'yourdatagrid event
If SortStr = e.SortExpression Then
If Trim(SortDirection) = "Asc " Then
SortDirection = " Desc "
Else
SortDirection = " Asc "
End If
Else
SortStr = e.SortExpression
End If
ResetColumn()
Select Case e.SortExpression
Case "UserID " 'your column
SetArrow(SortDirection, 0, dagUsers)
Case "LastName " 'your column
SetArrow(SortDirection, 1, dagUsers)
Case "FirstName " 'your column
SetArrow(SortDirection, 2, dagUsers)
Case "IP " 'your column
SetArrow(SortDirection, 3, dagUsers)
End Select
binddata()
End Sub

Private Sub ResetColumn()
dagUsers.Columns(0).HeaderText = "UserID " 'your column
dagUsers.Columns(1).HeaderText = "LastName " 'your column
dagUsers.Columns(2).HeaderText = "FirstName " 'your column
dagUsers.Columns(3).HeaderText = "IP " 'your column
End Sub

Public Sub SetArrow(ByVal Direction As String, ByVal ColumnIndex As Integer, ByRef SortGrid As DataGrid)
If Trim(Direction) = "Asc " Then
SortGrid.Columns(ColumnIndex).HeaderText = SortGrid.Columns(ColumnIndex).HeaderText & " <img src= 'Images/ArrowUp.jpg ' border= '0 '> "
Else
SortGrid.Columns(ColumnIndex).HeaderText = SortGrid.Columns(ColumnIndex).HeaderText & " <img src= 'Images/ArrowDown.jpg ' border= '0 '> "
End If
End Sub
------解决方案--------------------