datagrid sort with autogeneratecolumn = false

Posted on 2005-04-16
Medium Priority
Last Modified: 2012-06-27

How can we sort a datagrid if the grid is set to autogenerate=false? sorting ASC then DSC using mouse lcik on the column header.
The grid is being populated by data from sql server.


    Sub Sort_Grid(sender As Object, e As DataGridSortCommandEventArgs)
            Dim SortExpression As String
            SortExpression = e.SortExpression.ToString()
            If SortMode = "Desc" Then
              SortMode = "Asc"
              SortExpression = SortExpression + " " + "Desc"
              SortMode = "Desc"
            End If
            Dim odataView as DataView = GenerateSource().DefaultView
    End Sub 'Sort_Grid
Question by:EdwardPeter
LVL 18

Accepted Solution

tusharashah earned 2000 total points
ID: 13797162
The above code will work for 2 way sort, just make sure following things:

1) In your Datagird specify SortExpression of each column that you want to Sort:

<asp:BoundColumn DataField="ColumnName" SortExpression="ColumnName" HeaderText="ColumnName"></asp:BoundColumn>

2) Declare SortMode Variable as shared with your class declaration:

Public Shared SortMode As String = "Asc"

3) write above code in Sort Command of DataGrid.


Author Comment

ID: 13797196

You're simply the best. Sadly my old account had expired need to create a new one.



Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question