default sort on gridview load

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

For performance reasons i can not set a sort order on a dataset returned from
a stored procedure. Ideally in the sp i'd set the company name as the order
and just load the gridview, however the joins are very complicated and this
causes the sp to take 20 time (at least) longer than when no ordering is
specified. I would create a temp table and sort this for the return, however,
ado.net can not see a temp table because it does not exist at the conclustion
of the sp. I REALLY do not want to use an inline adhoc query that joins 15
table and uses derived result sets to get all the information. The sp
performs very well so long as no attempt to order the result is made.

So here is my issue:
I need to set the default order to company name on the result set on initial
datagrid load. Is there a way to do this? And where? and How?

I think this one is an issue some others have faced and i'd really like you
help.

Thanks!
 
1. Create a "DataView" from your "DataSource"
2. Set the sort order and/or filters in the DataView. (see the .Sort
and .RowFilter properties)
3. Bind the dataview (not the datasource) to your GridView
 
will sorting then be handled as usual or are there extra steps needed when a
column is selected for alternate sorting such as the older datagrid?
 
When the user clicks on a column (to sort that column), you'll have to
handle the appropriate "sorting" event.

In the "sorting" event-handler, you need to:
- requery the data
- create a dataView from the dataset or datatable
- set the sorting on the dataview
- bind the dataview to the grid

Additionally, there are steps you need to take to set the correct up/
down arrow in the grid column header if you want a graphic to show
which column is sorted. Some people use images. Some people use
these unicode chars:&#9650" and "&#9660" to show up/down arrows. For
compatibility reasons, the images are best. I don't have the code in
front of me, but I remember being very "surprised" at how not-so-easy
this was.
 
Back
Top