Sorting DataGrid

  • Thread starter Thread starter Diego F.
  • Start date Start date
D

Diego F.

Hi. I need to sort datagrid fields. What are the steps I had to follow?

If I sort a DataGrid, does the bound DataTable alter its fields also or it's
independent?
 
Hi Diego,

To answer your final query, if you need to display data in a sorted order,
you would need to use a Dataview instead of a Dataset as Dataset does
not support the Sort Property.

Next, in your Update event, i.e, DataGrid1_UpdateCommand, you can
write the following code snippet:

DataView myDataView = ds.Tables(4).DefaultView;
// By default, the first column sorted ascending.
myDataView.Sort = "CoulmnName DESC";

Since the default order is Ascending, you would not need to use the
property.
However, you would still need to use a Dataview to get the default Sort
order

Following link describes the property in detail:

[DataView.Sort Property]
http://msdn.microsoft.com/library/d...tml/frlrfsystemdatadataviewclasssorttopic.asp

HTH

Mona[Grapecity]
 
In order to conduct sorting, you have to assign the datagrid’s AllowSorting
to true. If you set AutoGenerateColumns to false, you also need to assign
SortExpression = “DataFieldName†for each sort column. Then in
datagrid_SortCommand event implement sorting:

dataview.Sort = e.SortCommand;
datagrid.DataSource = dataview;
datagrid.DataBind();


HTH

Elton Wang
(e-mail address removed)
 

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

Back
Top