ObjectDataSource and GridView SortExpression with multiple columns problem

Discussion in 'ASP .Net' started by Bogdan, Jul 28, 2009.

  1. Bogdan

    Bogdan Guest

    Hi,

    I've spent some time reading articles on gridview sorting when sort
    expression consists of multiple columns. I have to say that I'm as confused
    as ever.

    Could someone please help me out on this one? What do I need to do in order
    to utilize GridView's auto-sorting and be able to set the sort expression to
    multiple columns?

    Some articles mentioned that if I set SortExpression="column1,column2" and
    try to sort in descending order then GV passes an expression of the
    following format to the data source object: "column1, column2 DESC" and this
    is why descending sort is never applied to the first column? Could someone
    please confirm this? Is there an 'official' doc from MS that deals with it?

    If the above is true, is there a workaround/solution?

    I'd appreciate _any_ suggestions.
    Thanks,
    Bogdan
     
    Bogdan, Jul 28, 2009
    #1
    1. Advertisements

  2. Re: ObjectDataSource and GridView SortExpression with multiplecolumns problem

    On Jul 28, 11:30 pm, "Bogdan" <> wrote:
    > Hi,
    >
    > I've spent some time reading articles on gridview sorting when sort
    > expression consists of multiple columns.  I have to say that I'm as confused
    > as ever.
    >
    > Could someone please help me out on this one?  What do I need to do in order
    > to utilize GridView's auto-sorting and be able to set the sort expression to
    > multiple columns?
    >
    > Some articles mentioned that if I set SortExpression="column1,column2" and
    > try to sort in descending order then GV passes  an expression of the
    > following format to the data source object: "column1, column2 DESC" and this
    > is why descending sort is never applied to the first column?  Could someone
    > please confirm this?  Is there an 'official' doc from MS that deals with it?
    >
    > If the above is true, is there a workaround/solution?
    >
    > I'd appreciate _any_ suggestions.
    > Thanks,
    > Bogdan


    Hi Bogdan

    This is true. The SortExpression property is a string and could
    contain a comma-separated list of the fields by which to sort. The
    SortDirection property used a SortDirection datatype and could contain
    one of two SortDirection values: Ascending or Descending. So, when
    GridView has multiple columns to sort, then SortExpression property
    contains a list and SortDirection just one possible value and a
    GridView generates something like this

    "FirstName, LastName DESC"-- where first column is still sorted in
    ascending order.

    I found this a bit stupid but this is the way it works

    MSDN:
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortexpression.aspx
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortdirection.aspx

    Here's an example of how to do a workaround
    http://aspalliance.com/666_Extending_the_GridViews_Sorting_Capabilities.all

    Hope this helps
     
    Alexey Smirnov, Jul 31, 2009
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmFtZXMgUm9zZXdlbGw=?=

    GridView and SortExpression after Column Removed

    =?Utf-8?B?SmFtZXMgUm9zZXdlbGw=?=, Feb 26, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,428
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Feb 27, 2006
  2. Jacksm
    Replies:
    2
    Views:
    1,140
    Paul Chalekian
    Nov 21, 2006
  3. Steven Nagy

    GridView ObjectDataSource hidden columns

    Steven Nagy, Feb 7, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    714
    Steven Nagy
    Feb 8, 2007
  4. =?Utf-8?B?SmF5IFBvbmR5?=
    Replies:
    2
    Views:
    931
    Steven Cheng[MSFT]
    Nov 14, 2007
  5. Joel Krist

    ObjectDataSource/GridView with dynamic columns

    Joel Krist, May 18, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    369
    Joel Krist
    May 18, 2006
  6. Urs Eichmann
    Replies:
    2
    Views:
    400
    Urs Eichmann
    Sep 22, 2006
  7. Philip

    GridView - ObjectDataSource - Dynamic Columns

    Philip, Oct 24, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    450
  8. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    1,153
    Vinki
    Apr 25, 2007
Loading...