I have the DOB dropdown and I already got the Day and Year field out to display but not the month. Is there any ways that you could help?
Here are my codes:
int col = 0;
arrDOB = new ArrayList();
DateTime dob = Convert.ToDateTime(varDOB);
if (varDOB != "")
{
if (col == 0)
{
//Populates the day
ddlDay.Items.FindByValue(Convert.ToString(dob.Day)).Selected = true;
arrDOB.Add(dob.Day);
}
else if (col == 1)
{
//Populates the month
ddlMonth.SelectedValue = dob.Month.ToString();
// ddlMonth.Items.FindByValue(Convert.ToString(dob.Month)).Selected = true;
arrDOB.Add(dob.Month);
// ddlMonth.Visible = true;
}
//Populates the year
ddlYear.Items.FindByValue(Convert.ToString(dob.Year)).Selected = true;
arrDOB.Add(dob.Year);
}
Thanks. :))
Santhosh NPosted Jan 11, 2010, 11:55 PM
arrDOB = new ArrayList();
DateTime dob = Convert.ToDateTime(varDOB);
if (varDOB != "")
{
//Populates the day
ddlDay.Items.FindByValue(Convert.ToString(dob.Day)).Selected = true;
arrDOB.Add(dob.Day);
//Populates the month
ddlMonth.SelectedValue = dob.Month.ToString();
// ddlMonth.Items.FindByValue(Convert.ToString(dob.Month)).Selected = true;
arrDOB.Add(dob.Month);
// ddlMonth.Visible = true;
//Populates the year
ddlYear.Items.FindByValue(Convert.ToString(dob.Year)).Selected = true;
arrDOB.Add(dob.Year);
}
Nilanka DharmadasaPosted Jan 11, 2010, 11:20 PM
I guess your month dropdownlist has the names of the months. Like January, February... Not 1,2,3... That's the reason.
Change your 'ddlMonth.SelectedValue = dob.Month.ToString();' line to following.
ddlMonth.SelectedValue = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(
dob.Month);
If my answer helpful, please tick 'Do you like this answer' checkbox.