I have a dropdownlist that use an objectdatasource as its datasource. On the databound event I am adding another list item to the dropdownlist with this statement:
Now the dropdownlist is in a formview so I edited its databindings to a field being returned from a database. If the field has a value it works fine but if the field is null it errors out with the following message:
System.ArgumentOutOfRangeException: 'DropDownListPurchaseDivision' has a SelectedValue which is invalid because it does not exist in the list of items
Is there anyway to compensate for null values in this situation? Thanks!
Code:
DropDownList ddl = (DropDownList)sender;
ddl.Items.Insert(0, new ListItem("- select Purchasing Division", ""));
System.ArgumentOutOfRangeException: 'DropDownListPurchaseDivision' has a SelectedValue which is invalid because it does not exist in the list of items
Is there anyway to compensate for null values in this situation? Thanks!