Sort Grid from Column Header and Drop Down???

Discussion in 'ASP .Net Web Controls' started by DBLWizard, Apr 11, 2007.

  1. DBLWizard

    DBLWizard Guest

    Howdy All,

    I posted a message on the topic earlier and thought I had it solved
    but in testing have found problems. I have a Templated GridView
    control on a webpage bound to an ObjectDataSource. There are 3
    columns that are "Sortable" That sorting works fine until I add the
    dropdown with a "refresh" button into the mix. The only way that I
    have found to sort the grid from the dropdown requires the following
    code.

    When I set the e.Arguments.SortExpression it causes the grid to get
    sorted the problem is the Grid properties do not reflect this change.
    So when you next click on the grid column to sort it has the wrong
    information as to which column is sorted and what direction is
    sorted. So the first click on the column header the results are
    unpredicable. Is there a better way to do this?

    Any help would be greatly appreciated.

    Thanks

    dbl

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
    sortColumn =
    Convert.ToInt16(cboSortBy.SelectedValue.Substring(0, 1));
    sortExpression =
    grdUpcoming.Columns[sortColumn].SortExpression;

    if (cboSortBy.SelectedValue.EndsWith("A"))
    {
    sortDirection = "ASC";
    }
    else if (cboSortBy.SelectedValue.EndsWith("D"))
    {
    sortDirection = "DESC";
    }
    else
    {
    throw new Exception("Invalid sort by Value");
    }
    grdUpcoming.DataBind();
    }

    protected void ObjectDataSource1_Selecting(object sender,
    ObjectDataSourceSelectingEventArgs e)
    {
    if (!e.ExecutingSelectCount)
    {
    if (sortExpression != "")
    {
    e.Arguments.SortExpression = sortExpression + " "
    + sortDirection;
    }
    else
    {
    cboSortBy.SelectedValue =
    GetSortColumnIndex().ToString() +
    grdUpcoming.SortDirection.ToString().Substring(0, 1).ToUpper();

    }
    }
    }
    DBLWizard, Apr 11, 2007
    #1
    1. Advertising

  2. DBLWizard

    marss Guest

    DBLWizard wrote:

    > So when you next click on the grid column to sort it has the wrong
    > information as to which column is sorted and what direction is
    > sorted.


    Store sorting information in the ViewState.

    Maybe you will find it usefull.
    http://www.codeproject.com/useritems/gridviewex.asp

    Regards
    marss, Apr 12, 2007
    #2
    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. SirPoonga
    Replies:
    2
    Views:
    738
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    996
    weiwei
    Jan 5, 2007
  3. DBLWizard
    Replies:
    0
    Views:
    384
    DBLWizard
    Apr 11, 2007
  4. msimmons
    Replies:
    0
    Views:
    452
    msimmons
    Jul 16, 2009
  5. Navin
    Replies:
    1
    Views:
    668
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page