Sorting in Gridview

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HI

I am a asp.net 2.0 newbie and i am trying to sort on a gridview. I am using
a storedprocedure for a datasource, is this possible and how?

thanks

B
 
HI

I am a asp.net 2.0 newbie and i am trying to sort on a gridview. I am using
a storedprocedure for a datasource, is this possible and how?

1. Enable sorting in datagrid:

<asp:DataGrid id="DataGrid1" AllowSorting="True"
OnSortCommand="SortGrid"...
.....
<asp:BoundColumn DataField="nameOfColumn"
SortExpression="nameOfColumn" />

2. Create SortGrid

Sub BindGrid()

Dim dr As Data.DataSet = ... your source

Dim dv As New DataView()

dv = dr.Tables(0).DefaultView
DataGrid1.DataSource = dv

dv.Sort = SortField

DataGrid1.DataBind()

dr = Nothing

End Sub

That's all!
 
Back
Top