Google Answers Logo
View Question
 
Q: Auto Reverse Sort in VB.NET DataGrids ( No Answer,   0 Comments )
Question  
Subject: Auto Reverse Sort in VB.NET DataGrids
Category: Computers > Programming
Asked by: bdwgarth-ga
List Price: $5.00
Posted: 28 Sep 2004 17:04 PDT
Expires: 05 Oct 2004 14:14 PDT
Question ID: 407679
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
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

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 Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy