Here is some code for sorting:
First you should set the "AllowSorting" property to true in the dataGrid
Control and give the eventhandler name.
<asp
ataGrid id="DataGrid1" OnSortCommand="Sort_Grid"
AutoGenerateColumns="False" AllowSorting="True" runat="server">
In the event handler do your sorting. You didn't specify what your data
source is. In the event handler you could connect to your database with a
modified select statement with "Order by" statement, sorting it by whatever
the selected column is. (you get hold of what is selected by
e.SortExpression in the handler)
The Dataview also provides a good way to sort. An example is below:
void Sort_Grid(Object sender, DataGridSortCommandEventArgs e)
{
//If dt is your datasource:
DataView dv = new DataView(dt);
dv.Sort = e.SortExpression;
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}
Hope this helps