0

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") %>'>
</asp:DropDownList>


Any help would be greatly appreciated.

thanks
Deeee

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by Techscrip
0

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

0

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?

Regards,
Deeee

0

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.DataBind()
drpSponsor.Items.FindByText("Sponsor").Selected = True
End If

End Sub


hope this might help,

http://msdn2.microsoft.com/en-us/library/xy14hwwb(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(VS.80).aspx

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.