Hi all,
I was wondering of an easy way to set the selected value of a drop down list by using a value retrieved from the database. Here is my code:
On the front end .aspx page the drop down list has a bound data source so I need to set the selected value of this drop down list to the database one.
Many thanks in advance.
I was wondering of an easy way to set the selected value of a drop down list by using a value retrieved from the database. Here is my code:
Code:
SqlCommand cmdUser = new SqlCommand("SELECT ID FROM Tble WHERE ID = 2", connSQL);
cmdUser.CommandType = CommandType.Text;
SqlDataReader rdrUser = cmdUser.ExecuteReader();
while (rdrUser.Read())
{
ddlID.SelectedValue = rdrUser.GetString(0);
}
rdrUser.Close();
Many thanks in advance.
Comment