[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Custom sorting in GridView

AVL

10/21/2008 7:38:00 AM

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..??.


1 Answer

Ashutosh Bhawasinka

10/30/2008 4:19:00 AM

0

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

AVL wrote:
> 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..??.
>
>
>