DataGrid with client side functionality

  • Thread starter Thread starter Mark Goldin
  • Start date Start date
M

Mark Goldin

Can someone provide a code (C#) for highlighting of a selected row and
sorting when a header is clicked?

Thanks
 
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:DataGrid 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
 
Back
Top