Custom sorting in GridView

A

AVL

Hi
I want to implment cusotm sorting in gridview...
Ive a dropdown box on my page where ive all the fields(columsn) to be sorted..
whenever hte user selects the value in the dropdown , the gridview should be
sorted...

As of now, whenever user selects a value in the dropdown , Im rebinding
the grid with sorting applied....
but this is hittng the page performance...

so Im thinking to get the datasource associated with the girdview and then
sort the data...
Ive used gridview,DataSource property to retrieve the datatable associated
with it..
but its always returning null.

can some one help me out with this issue.
why is the DataSource property returnign null though the data is present...
How the .net has implemented the default sorting without reloading..??.
 
A

Ashutosh Bhawasinka

I you want to use the data source, you need to create it and assign it
to the data grid view. DataGrid view doesn't create a data source for
manually inserted items.

If the data you are displaying in the grid is not from a database you
need to create a untyped data set. Which will consist of manually
creating the tables and adding it to the data set. Assigning/setting the
dataset to the data grid view.
After thats done you need to add the rows in the table added to the dataset.
something like this

DataSet ds= new DataSet();
DataTable dt= new DataTable("MyTable1");
dt.Columns.AddRange(new DataColumn[]{
new DataColumn("Column1", typeof(string)),
new DataColumn("Column2", typeof(string)),
new DataColumn("Column3", typeof(string)),
});
ds.Tables.Add(dt);
//now add rows

Then you can manage the view (sorting) using the DataTable.DefaultView
property.

Thanks & Regards,
Ashutosh
 

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

Top