After a bit of monkeying around with the translated code I had this Sub.
<script runat="server"> Sub GridView1_RowCreated(ByVal sender
As Object, ByVal e
As GridViewRowEventArgs) If Not (e.Row Is Nothing)
AndAlso e.Row.RowType = DataControlRowType.Header
Then
For Each cell As TableCell
In e.Row.Cells If cell.HasControls Then
Dim button As LinkButton =
DirectCast(cell.Controls(0), LinkButton) If Not (button Is Nothing)
Then
Dim image As Image =
New Image
image.ImageUrl = "images/default.gif" If GridView1.SortExpression = button.CommandArgument
Then
If GridView1.SortDirection = SortDirection.Ascending
Then
image.ImageUrl = "images/uarrow.gif" Else
image.ImageUrl = "images/darrow.gif" End If
End If
cell.Controls.Add(image) End If
End If
Next
End If
End Sub
</script>
Added "OnRowCreated" and the Sub "GridView1_RowCreated" to the gridview and bam I have sorting arrows for my gridview.
Also if your gridview ID is named something other that GridView1 you'll need to change the few references to GridView1 in the sub.
I hope this save as much hair as I have pulled out looking for an sorting image solution. :P
ethanmcdonal...
Member
10 Points
2 Posts
Re: Up Down GridView Icon Image for Column Sorting
Oct 10, 2006 05:06 PM|LINK
Thanks for the link I translated the C# code from this site to VB.
http://fredrik.nsquared2.com/viewpost.aspx?PostID=185
After a bit of monkeying around with the translated code I had this Sub.
<script runat="server">
Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If Not (e.Row Is Nothing) AndAlso e.Row.RowType = DataControlRowType.Header Then
For Each cell As TableCell In e.Row.Cells
If cell.HasControls Then
Dim button As LinkButton = DirectCast(cell.Controls(0), LinkButton)
If Not (button Is Nothing) Then
Dim image As Image = New Image
image.ImageUrl = "images/default.gif"
If GridView1.SortExpression = button.CommandArgument Then
If GridView1.SortDirection = SortDirection.Ascending Then
image.ImageUrl = "images/uarrow.gif"
Else
image.ImageUrl = "images/darrow.gif"
End If
End If
cell.Controls.Add(image)
End If
End If
Next
End If
End Sub
</script>
<asp: code stuff... Blah! />
<asp:GridView OnRowCreated="GridView1_RowCreated" ID="GridView1" runat="server" AllowSorting="True" >
Added "OnRowCreated" and the Sub "GridView1_RowCreated" to the gridview and bam I have sorting arrows for my gridview.
Also if your gridview ID is named something other that GridView1 you'll need to change the few references to GridView1 in the sub.
I hope this save as much hair as I have pulled out looking for an sorting image solution. :P
-Ethan
GridView GridView Sorting GridView editing sorting sort icons