DataGrid with client side functionality

M

Mark Goldin

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

Thanks
 
M

Martha[MSFT]

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
 

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