Datagrid Sorting using DataSource
-
I would like to know if there is anyway we can do a sorting of the Datagrid columns by retreiving the datasource and doing an order by on that Datasource instead of having to make a call to the DB that appends the appropriate ORDER BY clause to the SQL that changes the dataset returned back to the datagrid. Basically I wnat to figure out if it is possible to implement Datagrid sorting without having to perform a Database hit every time a sort operation is done. Any ideas?
-
I would like to know if there is anyway we can do a sorting of the Datagrid columns by retreiving the datasource and doing an order by on that Datasource instead of having to make a call to the DB that appends the appropriate ORDER BY clause to the SQL that changes the dataset returned back to the datagrid. Basically I wnat to figure out if it is possible to implement Datagrid sorting without having to perform a Database hit every time a sort operation is done. Any ideas?
One thing that you can do is to save the dataset to session (this will prevent the trip to the database) and create a Dataview that is bound to that dataset. The DataGrid is then bound to the DataView. The code would look something like this... System.Data.DataSet ds = new System.Data.DataSet(); System.Data.DataView dv = new System.Data.DataView(); dv.Table = ds.Tables[0]; dv.Sort = "FirtName Asc";