Multiple DataBinds fail to reflect change in DataView Sort

R

RRB

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
 
R

RRB

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top