GridView and SortExpression after Column Removed

Discussion in 'ASP .Net' started by =?Utf-8?B?SmFtZXMgUm9zZXdlbGw=?=, Feb 26, 2006.

  1. I'm getting an error in the following scenario.

    - A GridView control is bound to an SQLDataSource.
    - The user selects a column for sorting.
    - Some time later in code the column used for sorting is removed and the
    SelectCommand SQL changed so that the field is not returned.
    - When the GridView is redisplayed an error occurs because the
    GridView.SortExpression is no longer a valid column.

    The SortExpression property of the GridView control is read only so it can't
    be set to null or changed.

    My question is how can I implement this behaviour without the error occuring?

    James
     
    =?Utf-8?B?SmFtZXMgUm9zZXdlbGw=?=, Feb 26, 2006
    #1
    1. Advertisements

  2. You can use the GridView.Sort method to set the sort order to a default
    expression after you hide a column
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sort(VS.80).aspx
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "James Rosewell" wrote:

    > I'm getting an error in the following scenario.
    >
    > - A GridView control is bound to an SQLDataSource.
    > - The user selects a column for sorting.
    > - Some time later in code the column used for sorting is removed and the
    > SelectCommand SQL changed so that the field is not returned.
    > - When the GridView is redisplayed an error occurs because the
    > GridView.SortExpression is no longer a valid column.
    >
    > The SortExpression property of the GridView control is read only so it can't
    > be set to null or changed.
    >
    > My question is how can I implement this behaviour without the error occuring?
    >
    > James
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Feb 27, 2006
    #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?UGF1bA==?=

    SortExpression makes SortCommand event not to trig

    =?Utf-8?B?UGF1bA==?=, Sep 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    494
    =?Utf-8?B?UGF1bA==?=
    Sep 22, 2005
  2. =?Utf-8?B?UGF1bA==?=

    Setting SortExpression programmatically

    =?Utf-8?B?UGF1bA==?=, Sep 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    6,119
    Kalpesh
    Sep 27, 2005
  3. fabrice
    Replies:
    1
    Views:
    817
    addup
    Dec 6, 2005
  4. JJ
    Replies:
    3
    Views:
    703
    Mark Rae
    Jun 8, 2007
  5. Bogdan
    Replies:
    1
    Views:
    3,874
    Alexey Smirnov
    Jul 31, 2009
Loading...

Share This Page