DateTime in dropdown

J

Jeff User

Hi all

The date values in my dropdown list appear as mm/dd/yyyy
Specifically, the day always contains 2 digits.
I need to set the selected index of the dropdown to the date that
equals another date value that does not use 2 digits for the day, if
the day is less that 10.
example
ddlBeginDate.SelectedIndex =
ddlBeginDate.Items.IndexOf(ddlBeginDate.Items.FindByText(someClass.BeginDate.ToShortDateString()));

does not work when the list contains 10/07/2006
and the value returned by someClass.BeginDate.ToShortDateString() is
10/7/2006

How can I set this list value to be the date returned frm the class?

Thanks
Jeff
 
J

justin creasy

Jeff,

Does the value have to be stored in SelectedIndex or could you
subscribe to the SelectedIndexChanged event, and when you catch the
event do the processing needed to remove the extra digit and place it
into another variable.
 
J

Jeff User

The dropdown is a list of dates. I have to find the index of the date
desired to set it as the selected item in the list. The desired value
being the date with only the 1 digit for the day, the list items being
the dates with 2 digits. I spose I can add the zero to the 1 digit day
to make it match the dropdown date format.
I was wondering if there was some way to use formating to get one to
look like the other.

Thanks
 
C

chanmm

Have you play with the Regional and Language Options in Control Panel and
see what is the effect?

chanmm
 
B

Bob Jones

Maybe I'm not understanding something here, but why don't you handle
the dates as DateTime objects? Date objects are easily compared. If
they are already strings - coming from the selection list- cast them to
DateTime, compare, then convert back to string.
 

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

Top