Hi all,

I have a bit of a problem with the selected value of a drop down box in asp.
i get this error:

'drpSponsor' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

my code for the binding is this:

<asp:DropDownList ID="drpSponsor" runat="server" DataSourceID="srcSponsorNames" DataTextField="Name"
DataValueField="Name" SelectedValue='<%# Bind("Sponsor") %>'>

Any help would be greatly appreciated.


um well look at the values in srcSponsorNames and im sure you will not see the value of Bind("Sponsor"). you are trying to select a value that does not exist

Thank you for your responce Plazmo, how else would i be able to retrieve a value that has been selected previously and is now stored in the table?


If your datasource is database table, i would suggest you to use code-behind file load event to set the selected value of drop-down list.

Private Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) handles MyBase.Load

If Not IsPostBack Then
drpSponsor.DataSource = DataSource
drpSponsor.DataTextField = "FieldName"
drpSponsor.DataValueField = "FieldValue"
drpSponsor.Items.FindByText("Sponsor").Selected = True
End If

End Sub

hope this might help,