ASP.NET將GridView表頭排序加上方向--vb.net
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowCreated
'GridView1.SortExpression.ToString()
If (e.Row.RowType = DataControlRowType.Header) Then
Dim myheader As TableCell
For Each myheader In e.Row.Cells '對每一格
If (myheader.HasControls()) Then
Dim LinkButton As LinkButton = myheader.Controls(0)
If LinkButton.CommandArgument = GridView1.SortExpression Then
'否為為排序欄位(myheader.Controls(0))
If (GridView1.SortDirection = SortDirection.Ascending) Then '依排序方向加入箭號
myheader.Controls.Add(New LiteralControl("▼"))
Else
myheader.Controls.Add(New LiteralControl("▲"))
End If
Else
If GridView1.SortExpression = "" And pag = 0 Then
If (GridView1.SortDirection = SortDirection.Ascending) Then '依排序方向加入箭號
myheader.Controls.Add(New LiteralControl("▼"))
Else
myheader.Controls.Add(New LiteralControl("▲"))
End If
pag = 1
End If
End If
End If
Next
End If
End Sub
留言列表