bidirectional sort with datagrid

D

DC Gringo

Can someone show me how to turn this into a bi-directional sort allowing
ascending and descending using the default datagrid allowsorting attribute?

FYI, Session("source") is an sqldataadapter
------------

Protected Sub SortCommand_OnClick(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
DataGrid2.SortCommand


Dim ds As DataSet = GetDataSource()
Dim dt As DataTable = ds.Tables(0)
dt.DefaultView.Sort = e.SortExpression

DataGrid2.DataSource = dt.DefaultView
DataGrid2.DataBind()

End Sub


Protected Function GetDataSource() As DataSet

Dim ds As New DataSet
Dim da As New SqlDataAdapter
da = Session("Source")
da.Fill(ds)
Return ds

End Function
 
D

DC Gringo

Thank you...

The problem I have with this example is it makes me manually enter the
Select Cases for each column. I'm looking for something that will
dynamically update with changes in the datagrid columns?

' Figure out the column index
Dim iIndex As Integer
Select case ColumnToSort.toUpper()
case "AU_FNAME"
iIndex = 0
case "AU_LNAME"
iIndex = 1
case "STATE"
iIndex = 3
End Select

_____
DC G
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top