datagrid bidirectional sorting

  • Thread starter Thread starter mark
  • Start date Start date
M

mark

i have populated a datagrid succesfully and enabled sort successfully except
its not bidirectional - how do i do this ?

this is my code for sorting

Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
DataGrid1.SortCommand
Dim strConn As String = connectionstring
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim sql As String = "SELECT * FROM extensionlist ORDER BY " &
e.SortExpression
Dim da As New System.Data.sqlclient.SqlDataAdapter(sql, conn)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
conn.Close()
Label5.Text = e.SortExpression
End Sub

i know its something to do with adding DESC and ASC to the sql string but im
not sure how

thanks

mark
 
you are correct. all you have to do is..
keep a session variable holding asc or desc and next time when clicked,
toggle between asc and desc.

its Order by columnname asc/desc

Av.
 
Mark,

'Create a sort variable.

Dim Sort As String

'Check if sort is in viewstate
If Not ViewState.Item("Sort") Is Nothing Then
Sort = ViewState.Item("Sort")
'Toggle the sort
If Sort = "ASC" Then
Sort = "DESC"
Else
Sort = "ASC"
End If
Else
'First sort is ascending
Sort = "ASC"
End If

'Then tack it on to the select.

Dim sql As String = "SELECT * FROM extensionlist ORDER BY" &
e.SortExpression & " " & Sort

'Store the current sort in viewstate (or elsewhere for postback)
ViewState.Add("Sort", Sort)

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Hi Mark,

you may like to read this article

http://www.dotnetjunkies.com/Article/3061D828-4D4E-4381-BE9F-02589F55C72C..dcik

Regards
Ashish M Bhonkiya

i have populated a datagrid succesfully and enabled sort successfully except
its not bidirectional - how do i do this ?

this is my code for sorting

Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
DataGrid1.SortCommand
Dim strConn As String = connectionstring
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim sql As String = "SELECT * FROM extensionlist ORDER BY " &
e.SortExpression
Dim da As New System.Data.sqlclient.SqlDataAdapter(sql, conn)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
conn.Close()
Label5.Text = e.SortExpression
End Sub

i know its something to do with adding DESC and ASC to the sql string but im
not sure how

thanks

mark
 
Back
Top