Datagrid e.SortExpression is wrong

Discussion in 'ASP .Net Datagrid Control' started by therien.mike@gmail.com, Jun 9, 2006.

  1. Guest

    I have a Datagrid with the first 4 columns as blank and without a Sort
    Expression set. The remaining columns have the Sort Expression set.

    The page stores a ViewState variable named "CurrentSort", that contains
    the sort expression the user last selected. When the page is initially
    loaded, this value is set to "ID", which is not one of the sort
    expressions in my DataGrid.

    I have the following code that generates and Up/Down arrow depending on
    the sort:

    (ItemCreated event)...
    if (e.Item.ItemType == ListItemType.Header)
    {
    for (int i=0; i < this.dgData.Columns.Count; i++)
    {
    if (this._currentSort ==
    this.dgData.Columns.SortExpression)
    {
    TableCell cell = e.Item.Cells;
    System.Web.UI.HtmlControls.HtmlImage imgArrow = new HtmlImage();
    imgArrow.Src =(this._sortDirection==enuSortDirection.soAscending ?
    "images/up.gif" : "images/dn.gif");
    imgArrow.Alt = (this._sortDirection==enuSortDirection.soAscending ?
    "Sorted in Ascending order" : "Sorted in Descending order");
    cell.Controls.Add(imgArrow);
    break;
    }
    }

    On initial load, no arrow is produced because the initial sort order is
    not a column.

    When the user clicks on a column, SortCommand is raised with the passed
    e.SortExpression. The problem is, when the above code produces an
    arrow, the column that is returned with the SortCommand event is for
    the the next column in the grid, (Column ID + 1) instead of the column
    that was clicked. If the above code did not produce an arrow, then
    everything works fine.

    I was able to determine that when the grid is generated with an arrow,
    the "link" in the status bar shows "...ctl{#}..." where the {#} of the
    column is correct when no arrow is present and column + 1 when an arrow
    is present. It seems to add a number when I add an arrow.

    This is all done in .Net 1.1.xxxx

    Thanks to anyone that can shed some light on this problem...

    Thanks,
    Mike
     
    , Jun 9, 2006
    #1
    1. Advertising

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:
    478
    =?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,051
    Kalpesh
    Sep 27, 2005
  3. fabrice
    Replies:
    1
    Views:
    800
    addup
    Dec 6, 2005
  4. =?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,313
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Feb 27, 2006
  5. JJ
    Replies:
    3
    Views:
    681
    Mark Rae
    Jun 8, 2007
Loading...

Share This Page