SelectedValue which is invalid because it does not exist in the list of items

Posted by Bob Jones on Stack Overflow See other posts from Stack Overflow or by Bob Jones
Published on 2009-09-04T02:12:00Z Indexed on 2010/04/21 13:53 UTC
Read the original article Hit count: 433

I encounter this problem repeatedly, and haven't a clue what is causing it. I get an exception in the DataBind: "SelectedValue which is invalid because it does not exist in the list of items". Here are some important pieces of information:

1) I reload listOrgs periodically when the underlying data has changed. 2) The Organization.DTListAll call returns about 500 Int, String pairs. 3) There are no duplicate or null values in the returned data 4) After the first two lines below, listOrgs.Items.Count is 0, and the Selected Value is 0 5) The selected value when the DataBind operation executes is a value that is not in the set of ID values returned 6) All of the stuff I have found on line so far hasn't helped. 7) I am stumped!

listOrgs.Items.Clear(); listOrgs.SelectedValue = "0"; listOrgs.DataSource = new Organization().DTListAll(SiteID); listOrgs.DataTextField = "OrganizationName"; listOrgs.DataValueField = "OrganizationID"; listOrgs.DataBind();

Bob Jones

© Stack Overflow or respective owner

Related posts about dropdownlist

Related posts about selectedvalue