![]() |
|
|
| Subject:
Urgent: Reverse Sort in VB.NET DataGrids
Category: Computers > Programming Asked by: bdwgarth-ga List Price: $5.00 |
Posted:
05 Oct 2004 14:13 PDT
Expires: 04 Nov 2004 13:13 PST Question ID: 410753 |
I am seeking code for a solution to an auto reverse sort in a datagrid
for a web application in vb.net. It is a typical practice, on the
datagrid header click the text once to sort DESC, click the header
text again to sort ASC. I am having trouble finding functional code.
Below is the code for the sort, bindgrid, and datapage. It currently
only sorts in one direction. Thank you.
Public Sub BindGrid(ByVal strOrder As String)
Dim strSearch = ViewState("SearchProperty")
Dim CommandText As String
If strSearch = "" Then
CommandText = "SELECT * From Property ORDER BY " & strOrder & ""
Else
CommandText = "SELECT * From Property Where " & strSearch
& " ORDER BY " & strOrder & ""
End If
Dim sqlCommand As New SqlDataAdapter(CommandText, sqlConnection)
Dim ds As New DataSet
sqlCommand.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
sqlConnection.Close()
End Sub
Sub DataGrid_Page(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
If ViewState("SortExprValue") <> "" Then
BindGrid(ViewState("SortExprValue").ToString())
Else
BindGrid("Location")
End If
End Sub
Sub DataGrid_Sort(ByVal sender As Object, ByVal e As
DataGridSortCommandEventArgs)
DataGrid1.CurrentPageIndex = 0
ViewState("SortExprValue") = e.SortExpression
BindGrid(e.SortExpression)
End Sub |
|
| There is no answer at this time. |
|
| Subject:
Re: Urgent: Reverse Sort in VB.NET DataGrids
From: fahadhabib80-ga on 06 Oct 2004 04:14 PDT |
Hi,
The queries you are using has no ASC or DESC clause... and I suspect
it is not passing from your ViewState and this is the cause of sorting
problem.
The value of sortOrder variable will be LOCATION by default and
whatever value is passed from ViewState(("SortExprValue") ...
Try to modify ... Sub DataGrid_Page... as
Sub DataGrid_Page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
'** modification
if ViewState("SortDir") = "" then
ViewState("SortDir") = "ASC"
elseif ViewState("SortDir") = "ASC" then
ViewState("SortDir") = "DESC"
else
ViewState("SortDir") = "ASC"
'***
If ViewState("SortExprValue") <> "" Then
// Modification
BindGrid(ViewState("SortExprValue").ToString() & " " &
ViewState("SortDir").ToString())
Else
// Modification
BindGrid("Location" & " " & ViewState("SortDir").ToString()))
End If
End Sub
try this... I hope this will work...
Thanks and Regards
Fahad |
| Subject:
Re: Urgent: Reverse Sort in VB.NET DataGrids
From: bdwgarth-ga on 06 Oct 2004 12:32 PDT |
If the changes suggested, are in the datagird_page event handler, will this then change the Sort Direction if the datagrid Header Items are clicked once for ASC and click again for DESC to sort by critera of the header item that was clicked. It appears that the modifications in the code should occur in the datagrid_sort handler. Or I may be wrong, it just doesnt seem logically right. Thank you. Brett |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |