Hi,
How you fill the datagrid?, are you using a datatable?
If you're using a datatable you can use this code:
//When you get the data from (for instance :database)
DataView dv = new DataView();
dv=Yourdatatable.DefaultView;
Page.Session.Add("DataViewOriginal",dv);//put into the session the view
this.DataGrid1.DataSource=dv;//assign the data source
this.DataGrid1.DataBind();
//In your sortCommand method
if(Page.Session["DataViewOriginal"]!=null) //if exists the dataview in the
session
{
DataView dv=(DataView) Page.Session["DataViewOriginal"]; //take the view
dv.Sort=e.SortExpression;//sort the view by the name of the column header
clicked
this.DataGrid1.DataSource=dv; //assign the source
this.DataBind(); //show the info
}
Hope this helps.
Regards.
josema.
"Newbie" wrote:
Hello!
I need help in making my datagrid sortable by clicking a column header.
In the datagrid's property builder, Allow Sorting is checked. I am using a
Bound column and it's Sort Expression is set to the same value as the Data
Field value. But I dont know how to implement:
private void dgResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
}
Please help.