A DropDownList cannot have multiple items selected.
Dear Guys,
I have created a web user control with a function which populates dates,
this is code I have written
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
int CurrentDateYear = DateTime.Now.Year;
int CurrentDateMonth = DateTime.Now.Month;
int CurrentDateDay = DateTime.Now.Day;
DateTime LastMonthDate = DateTime.Today.AddMonths(-1);
int LastMonthDateYear = LastMonthDate.Year;
int LastMonthDateMonth = LastMonthDate.Month;
int LastMonthDateDay = LastMonthDate.Day;
this.PopulateBeginYear(LastMonthDateYear);
this.PopulateBeginMonth(LastMonthDateMonth);
this.PopulateBeginDay(LastMonthDateDay);
this.PopulateEndYear(CurrentDateYear);
this.PopulateEndMonth(CurrentDateMonth);
this.PopulateEndDay(CurrentDateDay);
}
public void PopulateBeginYear(int ly)
{
int max = DateTime.Now.Year + 5;
for(int i = 2000; i <= max; i++)
{
ListItem item = new ListItem(i.ToString(),i.ToString());
item.Selected = (i == ly);
ddlBeginYear.Items.Add(item);
}
}
public void PopulateBeginMonth(int lm)
{
for(int i = 1; i <= 12; i++)
{
ListItem item = new ListItem(i.ToString(),i.ToString());
item.Selected = (i == lm);
ddlBeginMonth.Items.Add(item);
}
}
public void PopulateBeginDay(int ld)
{
for(int i= 1; i<=31; i++)
{
ListItem item = new ListItem(i.ToString(),i.ToString());
item.Selected = (i == ld);
ddlBeginDay.Items.Add(item);
}
}
public void PopulateEndYear(int cy)
{
int max = DateTime.Now.Year + 5;
for(int i = 2000; i <= max; i++)
{
ListItem item = new ListItem(i.ToString(),i.ToString());
item.Selected = (i == cy);
ddlEndYear.Items.Add(item);
}
}
public void PopulateEndMonth(int cm)
{
for(int i = 1; i <= 12; i++)
{
ListItem item = new ListItem(i.ToString(),i.ToString());
item.Selected = (i == cm);
ddlEndMonth.Items.Add(item);
}
}
public void PopulateEndDay(int cd)
{
for(int i= 1; i<=31; i++)
{
ListItem item = new ListItem(i.ToString(),i.ToString());
item.Selected = (i == cd);
ddlEndDay.Items.Add(item);
}
}
public DateTime StartDate
{
get
{
return new DateTime(Convert.ToInt16(ddlBeginYear.SelectedItem.Value),Convert.ToInt16(ddlBeginMonth.SelectedItem .Value),Convert.ToInt16(ddlBeginDay.SelectedItem.Value));
}
}
public DateTime EndDate
{
get
{
return new DateTime(Convert.ToInt16(ddlEndYear.SelectedItem.Value),Convert.ToInt16(ddlEndMonth.SelectedItem.Val ue),Convert.ToInt16(ddlEndDay.SelectedItem.Value));
}
}
Then I used this usercontrol in another aspx form, then i got it populated the dates for some reason it gives me some wired error
A DropDownList cannot have multiple items selected.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: A DropDownList cannot have multiple items selected.
I am really stuck here, I really appreciate your help
have a good week end
dummy_pmgr