Problem Formatting Year

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • koonda
    New Member
    • Oct 2006
    • 34

    #1

    Problem Formatting Year

    Hi all,

    I am working on a project. Everything is working fine except the date formating. I have five listboxes and a dropdownlist box controls. The 5 listboxes I have populated from the underlying database view and dropdownlist box is populated by the date in the same view. When I select any values from the listboxes the information is displayed in the Repeater Control. I also want to select the date including the 5 listboxes to display the result in the Repeater but when I select the date which is 2006 from the Dropdownlist it give me this error message:

    " String was not recognized as a valid DateTime"

    I am adding listboxes and dropdownlist into the arraylist which works fine but the dropdownlist with the date won't work. I cannot figue out why is that. Here is the code I am using for Dropdownlist for the date I mean for the year 2006:


    if ((DropDownList1 .SelectedValue != null) && (DropDownList1. SelectedValue != ""))
    {

    DateTime d = Convert.ToDateT ime(DropDownLis t1.Text); // this line gives error


    string t = d.ToString("dd-mm-yyyy");
    Alist.Add(

    "OrderDate = CONVERT(DATETIM E, '" + t + "', 102)");
    }

    So it gives me this error : " String was not recognized as a valid DateTime". The whole code works fine for the NorthWind the free database I tried as an example but not for this project

    Looking forward to your reply



    Koonda
  • joerozario
    New Member
    • Mar 2007
    • 60

    #2
    use

    DropDownList1.S electedValue

    or

    DropDownList1.T ext.toString()

    Comment

    • koonda
      New Member
      • Oct 2006
      • 34

      #3
      I used both but it didn't work. Is there any way or any code examples you can send me?

      Thanks for your help. looking forward to your reply.

      Koonda

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        My favourite method is:
        Code:
        DateTime.Parse(valuePassed,format,DateTimeStyles.None);

        Comment

        • koonda
          New Member
          • Oct 2006
          • 34

          #5
          Hi, kenobewan

          Can you explain your code a little bit. I tried your code but still it didn't work.
          Looking forward to your reply
          Thanks

          Koonda

          Comment

          Working...