Sorting in Gridview

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
 
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?

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top