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

Discussion in 'ASP .Net Datagrid Control' started by cindy, Mar 31, 2006.

  1. cindy

    cindy Guest

    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

    --
    cindy
     
    cindy, Mar 31, 2006
    #1
    1. Advertising

  2. 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.)
     
    Steven Cheng[MSFT], Mar 31, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hessam
    Replies:
    0
    Views:
    2,189
    Hessam
    Aug 8, 2003
  2. =?Utf-8?B?UmFqZXNoIHNvbmk=?=

    'System.String[]' from its string representation 'String[] Array'

    =?Utf-8?B?UmFqZXNoIHNvbmk=?=, May 4, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,808
    =?Utf-8?B?UmFqZXNoIHNvbmk=?=
    May 4, 2006
  3. mkhmer

    datagrid sort Date column as string

    mkhmer, Jul 3, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    131
    mkhmer
    Jul 3, 2006
  4. mkhmer

    Datagrid sort date column as string

    mkhmer, Jul 3, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    139
    Bruno Alexandre
    Jul 3, 2006
  5. Navin
    Replies:
    1
    Views:
    731
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page