DataGrid Sorting does not work

G

Guest

Hello,
I've a datagrid whose AllowSorting property is set to True. The datagrid is
bound to northwind table suppliers. I've handled the SortCommand event of the
datagrid control. But somehow the code is not working. The SortCommand event
handler is called, but the data shown in the grid is not sorted.

I've written the following code in the asp.net web appl.
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
sqlDataAdapter1.Fill(dataSet11);
DataGrid1.DataSource = dataSet11.Suppliers;
DataGrid1.DataBind();
}
}

private void DataGrid1_SortCommand(object source,
DataGridSortCommandEventArgs e)
{
sqlDataAdapter1.Fill(dataSet11);
DataView dv1 = new
DataView(dataSet11.Suppliers,"",e.SortExpression,DataViewRowState.CurrentRows);
dv1.Sort = e.SortExpression.ToString();
dv1.ApplyDefaultSort = false;
DataGrid1.DataSource = dv1;
DataGrid1.DataMember = "Suppliers";
DataGrid1.DataBind();
}

Can anybody point out the problem? The sorting works if I change the
SelectCommand property of the dataset and fill the dataset again with the new
command with an 'order by' clause. But what's wrong with the dataview
approach that I've demonstrated above?
 
G

Guest

Hello
The problem has been solved
I'd done the data binding of grid in the designer. Instead I should have
used only dynamic binding. Once I removed the binding in the designer, it
started working

Sameeksha
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top