Dynamic columns not sorting in DataGrid

Discussion in 'ASP .Net' started by =?Utf-8?B?amF2YXRvcGlh?=, Oct 2, 2004.

  1. I am creating a data grid's columns on the fly in my web page. The Bind
    operation works just fine, and data is displayed correctly when I change the
    layout of the grid (add/remove columns).

    I change the data grid by first removing all of the columns then adding each
    of the columns that I need for a particular report.

    My data grid has a "sort" handler:

    this.Report.SortCommand += new
    System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.Report_SortCommand);

    which is set in the InitializeComponent() method of my WebForm. I setup the
    column data model in my BindData() method of the form, which occurs AFTER the
    initialization (of course).

    This is my Report_SortCommand:

    private void Report_SortCommand(object source,
    System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
    {
    string expr = e.SortExpression;
    string oldexpr = (string)ViewState["DataSortExpression"];
    if(oldexpr == expr)
    {
    ViewState["DataSortExpression"] = expr + " DESC";
    }
    else
    {
    ViewState["DataSortExpression"] = expr;
    }
    BindData(); // -> This creates the re-creates the columns in the
    grid
    }

    So I put a breakpoint in the sort method and click on one of the column
    titles. The data grid goes blank and my breakpoint never gets hit.

    SOOO - when I remove the columns from a datagrid, does the sort event
    delegate get cleared ?? How do I get the sort event to call my custom sort
    handler?

    Thanks

    -- Jake
    =?Utf-8?B?amF2YXRvcGlh?=, Oct 2, 2004
    #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. Jordo
    Replies:
    0
    Views:
    450
    Jordo
    Oct 31, 2003
  2. avnrao
    Replies:
    3
    Views:
    3,647
    Elad Volpin
    Jun 6, 2004
  3. Replies:
    5
    Views:
    590
  4. Kostia

    Dynamic columns in DataGrid, Paging/Sorting and Data Caching

    Kostia, Apr 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    172
    Kostia
    Apr 16, 2004
  5. javatopia

    Dynamic columns and sorting/paging in DataGrid

    javatopia, Oct 19, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    126
    javatopia
    Oct 19, 2004
Loading...

Share This Page