datagrid sort string (is representation of date) as a DATE

C

cindy

I have a datatable with column datetime datatype from sql
I c# datagrid on webform with bound column to display values
I need to sort on values.
I sql the field value is a string so I make it pass the is string a valid
date test before I dump it into
dc = new DataColumn("reviseddate",Type.GetType("System.DateTime"));
dt.Columns.Add(dc);
the values are all over the place some have times some do not etc.
if not valid I want to assign DBNull to the column but I have not got that
syntax working right either. The datagrid column binds and displays, the
sort expression is the DataField. The only thing right that sort does is put
nulls on top (sort of right)
I guess the datagrid column is not type datetime. All day nowhere can I
find syntax for setting this bound column datatype. It is not dynamically
built, I have tried using with template column where is the property says
datagrid1.column whatever datatype = datetime. I guess if I could do that
then using DataFormatString="{0:d}" to make ugly datetime in short date
display would work or would it because DataFormatString="{0:d}" only works
for bound column.

Please why so hard?
Yes users have date and date with time strings in sql
But I do check the string is valid date
I put into datatable with column datatype datetime would ya think the
datagrid would hold on to datatype?





datatable columI tried just do sort with values in that ugly datetime
sql you know.
User entries to sql database pass the is it a date test but they have all
kinds o
 
S

Steven Cheng[MSFT]

Hi cindy,

Welcome to the ASPNET newsgroup.

As for the Sorting issue you mentioned, is the original data (for that
date/time) column of string type or date? If they're of string type, you
may need to convert them to datetime type through the DateTime.parse.
Based on my understanding, as long as the datagrid has been bound to the
datacolumn with correct type (of Datetime), the Sorting funciton should
work correctly according to the DateTime value.


Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top