Sort Routine Problem

T

Tom Carter

I have created a datagrid that has edit/update/cancel links and whose
header is sortable. I have one glitch which I hope sounds familar to
someone ...

I click the edit butoon and the textboxes are populated with data
from a different record than the record which I selected. This
problem occurs only after I sort the data.

What am I missing???

-- here's the code:

private void masterDataGrid_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
//Logic Handles Bi-Directional Sorting using SortHandler Hidden
Label
switch (SortHandler.Text.EndsWith(" ASC"))
{
case true :
SortHandler.Text = e.SortExpression.ToString () + " DESC";
break;
case false:
SortHandler.Text = e.SortExpression.ToString () + " ASC";
break;
}

dv.Sort = SortHandler.Text;
this.masterDataGrid.DataSource = dv;
this.masterDataGrid.DataBind();

}

-- heres the edit routine:
private void masterDataGrid_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.masterDataGrid.EditItemIndex = e.Item.ItemIndex;
this.masterDataGrid.DataBind ();
}
 
T

Tom Carter

Hi Team,

The problem is solved. I extrapolated the answer based on another
online answer. Essentially I needed to reset the Sort expression
before binding the data on each postback of the page.

i.e.
this.masterDataGrid.DataSource = dv;
dv.Sort = SortHandler.Text;
this.masterDataGrid.DataBind ();

Thanks anyhow -
 

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

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top