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?
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?