code_junkie

asp:DropDownList Error: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items

Nov 10th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. protected void ddSpecialty_PreRender(object sender, EventArgs e)
  2. {
  3. if (!ddSpecialty.Items.Contains(new ListItem(registration.Specialty)))
  4. ddSpecialty.Items.Add(registration.Specialty);
  5. ddSpecialty.SelectedValue = registration.Specialty;
  6. }
  7.  
  8. ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(value));
  9.  
  10. ddl.DataBound += (o,e) => ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(value));
  11.  
  12. if (ddl.Items.Contains(new ListItem(selectedFacility)))
  13. ddl.SelectedValue = selectedFacility;
Add Comment
Please, Sign In to add comment