I’ve got this dropdownlist which I populate using programming code:
while (teller < modellen.Length)
{
SqlCommand cmd2 = new SqlCommand("SELECT Mod_Naam FROM Model WHERE Mod_ID = '" + modellen[teller] + "' ", con);
string modnaam = (string)cmd2.ExecuteScalar();
ddlModel.Items.Add(new ListItem(modnaam, modellen[teller]));
teller++;
}
When I select something in the dropdownlist I get an autopostback (which I use to display a form on the screen for the selected item) but the selecteditem in the dropdownlist get’s lost during the postback. How do I keep the selecteditem through the postback?
You most likely are populating the dropdown in each request. Populate it only during first request i.e. not during the postbacks.