Reverse meaning of null in DataView

  • Thread starter Thread starter mdb
  • Start date Start date
M

mdb

I have a datagrid that is bound to a DataView, and it shows events and the
times that event started ("StartTime") and stopped ("EndTime"). If the event
has started but hasn't finished, then "EndTime" is null. When multiple lines
are displayed in the datagrid, if I sort by EndTime, then the null values end
up sorted incorrectly - they are sorted as if 'null' is minimum - but I need
them to sort as if 'null' is maximum...

Any suggestions? I cannot sort by StartTime (the description above is
simplified).
 
I can't think of any simple way to do this offhand. A couple of approaches
off the top of my head:

1) in your select statement the builds the data that the dataview is
pointing to, add a calculated column which is a number specifying the sort
order. In your SQL statement it should not be difficult to set all null
fields to sort order 1million or something. Then when your grid sorts on
that column, have it actually sort by the hidden sort order column.

2) Manually sort the data yourself into another data structure and bind to
that instead
 
I don't know how datagrids work, but if they use a sql query, try:

SELECT * FROM
ORDER BY isnull( endTime getdate() + 1)

- Steve
 

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

Back
Top