Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 9th, 2004, 10:14 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Machete
Default Dataview Sort: Multiple Databinds between Postback

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.

 
Old December 10th, 2004, 10:05 AM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Machete
Default

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.Curre nt);
            }
        }
    }

    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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VBA to Sort Multiple Columns meclive Excel VBA 1 July 30th, 2008 11:04 AM
Dynamic sort order or sort datatype kapy_kal XSLT 2 September 18th, 2007 02:10 PM
how to sort cross tab.sort based on row total joxa83 Crystal Reports 7 March 2nd, 2006 09:12 AM
Unable to sort using xsl sort command sly_jimmy_boy XSLT 3 June 17th, 2005 05:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.