|
-
Dec 19th, 2004, 06:40 PM
#1
Thread Starter
Addicted Member
Yes, another sorting question... (Losing my mind)
I've been stuck trying to sort a DataGrid for days -- any reason why I don't even see the grid here. Its a web form using access DB and has a call for the "sortCommand_Click" method from the grid.
Protected strOrderBy As String
Protected strSql As String = "SELECT Title, Author, File_Size, File_Type, Date, ID FROM Document"
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
strOrderBy = "Title ASC"
Session("Column") = "Title"
Session("Order") = "ASC"
BindTheData()
End If
End Sub
Sub BindTheData()
Dim ds As DataSet
Dim strSQL As String
ds = New DataSet
With daProducts
.SelectCommand.CommandText = strSQL
.Fill(ds)
End With
Dim dtCustomers As DataTable = ds.Tables("Document")
Dim dv As New DataView(dtCustomers)
dv.Sort = strOrderBy
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub
Sub SortCommand_Click(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
'Check to see if same column clicked again
If e.SortExpression.ToString() = Session("Column") Then
'Reverse the sort order
If Session("Order") = "ASC" Then
strOrderBy = e.SortExpression.ToString() & " DESC"
Session("Order") = "DESC"
Else
strOrderBy = e.SortExpression.ToString() & " ASC"
Session("Order") = "ASC"
End If
Else
'Different column selected, so default to ascending order
strOrderBy = e.SortExpression.ToString() & " ASC"
Session("Order") = "ASC"
End If
Session("Column") = e.SortExpression.ToString()
BindTheData()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|