views:

154

answers:

4

Hi all,

i am using gridview control to display records. i am using System.Collections.Generic List<> as datasource. I want to perform sort operation in gridview. Please help me

A: 

Programmatically,

You may need to sort the List<> before bind to gridview.

Or you may need to cast the gridview.DataSource to List<> explicitly and sort it.

If you want to sort the gridview on your GUI, then you need to set the gridview.AllowSorting property to true, then you should be able to sort.

Ngu Soon Hui
What guarantee is there the original `DataSource` is a `List<>` at all? What guarantee is there that it will remain the same type throughout the framework futures?
Joren
There's no guarantee, sadly
Ngu Soon Hui
+1  A: 

Setting AllowSorting property to true should be enough. Are you looking for custom sort?

danish
A: 

If you bind the data to a BindingSource, then bind the BindingSource to the grid, you should see it update properly when you sort, I believe.

Neil Barnwell
A: 

Hi Geetha,

Try this tutorial -

Sorting GridView Using IComparer

In summary you can use the IComparable interface to define a custom sorting depending on what column heading you click.

Hope this helps.

Josh

jj.matthews