How to set RadDatePicker textbox from database

6 posts, 0 answers
  1. Rob Venable
    Rob Venable avatar
    48 posts
    Member since:
    Dec 2009

    Posted 24 Jan 2010 Link to this post

    Hi,
     I have a contact page that retrieves contact information from the database. When I populate all fields from the database, how do I set the date for my RadDatePicker textbox to that of birthdate value from my contact object.

    ex: RadaDatePicker1.Value = Contact.Birthdate

    Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jan 2010 Link to this post

    Hi Rob,

    You can set the date for RadDatePicker as shown below.

    CS:
         RadDatePicker1.SelectedDate = (DateTime) Contact.Birthdate;

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 27 Jan 2010 Link to this post

    The proper way to set the selected date of a RadDatePicker control from the database would be like so:

    RadDatePicker1.DbSelectedDate = Contact.BirthDate;

    This way if the BirthDate is null, no error is thrown.
  5. Rob Venable
    Rob Venable avatar
    48 posts
    Member since:
    Dec 2009

    Posted 27 Jan 2010 Link to this post

    Hi,
    Thanks for the information. Both scenarios worked.
  6. Eric Larsen
    Eric Larsen avatar
    3 posts
    Member since:
    Jan 2006

    Posted 19 Aug 2013 Link to this post

    Error 32 Cannot convert type 'string' to 'System.DateTime' 

    please help.
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Aug 2013 Link to this post

    Hi Eric,

    Please try the following C# code.

    C#:
    RadDatePicker1.SelectedDate = DateTime.ParseExact(datestring, "M/d/yyyy", CultureInfo.InvariantCulture);

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017