How can I sort datagrid?

I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Usually what you do is sort the datagrid's datasource , if it's a
dataview/dataset you can use a Dataview for it.

I think I remember an article from Dino Esposito in MSDN magazine where he
sorted a HTML table ( which is the result of a datagrid in the client) try
searching in the MSDN archives.


Cheers,
 
S

Scott M.

Please don't cross-post. Here is your answer:


Private Sub dg_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
dg.PageIndexChanged
dg.CurrentPageIndex = e.NewPageIndex

'Sort the new page according to the last sort criteria
Dim dv As New DataView(dsCusts.Tables(0))
dv.Sort = ViewState.Item("lastSort")
dg.DataSource = dv

dg.DataBind()
End Sub

Private Sub dg_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
dg.SortCommand
Dim dv As New DataView(dsCusts.Tables(0))
dv.Sort = e.SortExpression
dg.DataSource = dv
dg.DataBind()

'Store the desired sort criteria so that it can be applied when
paging occurs
ViewState.Add("lastSort", e.SortExpression)
End Sub
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top