bidirectional sort with datagrid

  • Thread starter Thread starter DC Gringo
  • Start date Start date
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
 
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
 
Back
Top