I have several DropdownList, however there are two on which I am using SelectedIndexChange event. I am trying to get data from Database and fill respective DropdownList with values. Earlier I had an issue where both Dropdownlist gets same value, whichever code is written later. Then somehow that was fixed then I am getting this error .
Cannot have multiple items selected in a DropDownList.
Heres how I am getting data from database :
string sqlqry = "select * from Newenrollee where enrollecode=@enrollecode ";
//SqlCommand cmd = new SqlCommand(sqlqry, conn);
using (var cmd = new SqlCommand(sqlqry, conn))
{
cmd.Parameters.AddWithValue("@enrollecode", txtenrolleecode.Text);
dt.Rows.Clear();
da1 = new SqlDataAdapter(cmd);
da1.Fill(dt);
if (dt.Rows.Count > 0)
{
string regdate = (Convert.ToDateTime(dt.Rows[0]["dateofappointment"])).ToString();
DDLAPDay.Text = regdate.Substring(0, 2);
int mnthAD = (Convert.ToDateTime(dt.Rows[0]["dateofappointment"])).Month;
string mnthAD1 = "";
if (mnthAD > 0 && mnthAD < 10)
mnthAD1 = "0" + mnthAD.ToString();
else
mnthAD1 = mnthAD.ToString();
DDLADMonth.Text = mnthAD1;
DDLADYear.ClearSelection();
DDLADYear.Text = (Convert.ToDateTime(dt.Rows[0]["dateofappointment"])).Year.ToString();
DDLDay.Text = DOB.Text.Substring(0, 2);
int daydob = (Convert.ToDateTime(dt.Rows[0]["DOB"])).Month;
string daydob1 = "";
if (daydob > 0 && daydob < 10)
daydob1 = "0" + daydob.ToString();
else
daydob1 = daydob.ToString();
DDLMonth.Text = daydob1.ToString();
DDLYear.ClearSelection();
DDLYear.Text = (Convert.ToDateTime(dt.Rows[0]["DOB"])).Year.ToString();
}
}
These are the Dropdownlist that I am using. Let me know what is wrong. Thanks.