Multiple DataBinds fail to reflect change in DataView Sort

Discussion in 'ASP .Net Datagrid Control' started by RRB, Dec 9, 2004.

  1. RRB

    RRB Guest

    Hello all,

    I have constructed a datatable that is a subset of my dataset. I use a
    cached dataview as the datasource for my datagrid.
    For performance reasons, I have disabled viewstate on my datagrid and
    thus I must perform a databind on postback prior to additional
    processing.

    Where I've run into a problem is with sorting. I am supporting sortable
    columns by button controls in the column header. The intended flow is:

    - When a header button is clicked, a postback occurs, I bind the
    datagrid first, to enable ASP.Net to invoke my event handler.

    - the event handler executes some logic to determine the new sort column
    and direction, and sets the sort property on the cached dataview.

    - finally, the method responsible for rebinding the datagrid is called.

    What I have observed from my debugging is that whatever the value of the
    sort property on my dataview prior to my INITIAL databind upon postback,
    will be the sort order reflected in the datagrid upon response to the
    user. In other words, my SECOND databind is ignored.

    If I repeat the cycle by clicking yet another column (or the same
    column), I will see in the resulting datagrid the sort order I should
    have seen in the PRIOR response. So, now the displayed sort is now
    always one behind!

    My only theory is that maybe datagrid is not detecting that I've changed
    the sort order and is failing to reorder the rows. But to be honest,
    I'm at wit's end and I'm hoping someone can help me figure out what I
    may be doing wrong.

    ======================

    blackbox testing prerequisites:
    1 white box
    1 black marker
    1 idiot

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    RRB, Dec 9, 2004
    #1
    1. Advertising

  2. RRB

    RRB Guest

    Hi again, here's the relevant code snippets:

    Here you go, and thank you for taking a look!

    // this method is called by:
    // Page_Load()
    // columnHeader_Click()
    private void RestoreResults()
    {
    if (resultsGrid.Columns.Count == 0) // my columns are dynamic, so I
    cache them
    {
    object data = Session["ResultsGridColumns"];

    if (data != null)
    {
    IEnumerator cols =
    ((DataGridColumnCollection)data).GetEnumerator();

    while (cols.MoveNext())
    {
    resultsGrid.Columns.Add((DataGridColumn)cols.Current);
    }
    }
    }

    if (resultsGrid.DataSource == null) // might be first call from
    postback
    {
    resultsGrid.DataSource = Search.ResultsFilter; // my cached
    dataview
    }

    resultsGrid.DataBind();
    }


    public void columnHeader_Click(Object sender, EventArgs e)
    {
    Button colBtn = (Button) sender;
    CTSGridContext.NewSortColumnID = colBtn.Text; // helper class for
    later datagriditem rendering
    DataView view = Search.ResultsFilter;

    // ... SNIPPED: Some logic to determine actual column name and sort
    order


    if (CTSGridContext.NewSortAscending)
    {
    view.Sort = string.Format("{0}",
    CTSGridContext.NewSortColumnID);
    }
    else
    {
    view.Sort = string.Format("{0} DESC",
    CTSGridContext.NewSortColumnID);
    }

    RestoreResults();
    }


    So, the execution order is:
    Page_Load
    RestoreResults // here I do my intial databind
    columnHeader_Click // here I set my dataview sort
    RestoreResults // rebind the datagrid

    ======================

    blackbox testing prerequisites:
    1 white box
    1 black marker
    1 idiot

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    RRB, Dec 10, 2004
    #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. Mike Johnson

    2 databinds in 1 parameter

    Mike Johnson, Apr 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,046
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Apr 2, 2004
  2. =?Utf-8?B?SSBhbSBTYW0=?=

    Multiple DataBinds off one DataSet

    =?Utf-8?B?SSBhbSBTYW0=?=, Mar 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    409
    Karl Seguin
    Mar 16, 2005
  3. =?Utf-8?B?Unlv?=
    Replies:
    0
    Views:
    527
    =?Utf-8?B?Unlv?=
    Nov 21, 2005
  4. =?Utf-8?B?V2VzbGV5IERhdmlzLCBHZW5lcmFsIER5bmFtaWNz

    GridView auto databinds for any Postback?

    =?Utf-8?B?V2VzbGV5IERhdmlzLCBHZW5lcmFsIER5bmFtaWNz, May 14, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    595
    =?Utf-8?B?YnVybG8=?=
    May 15, 2007
  5. CodeMonkey
    Replies:
    1
    Views:
    738
    joyal jhaveri
    Feb 4, 2011
Loading...

Share This Page