0

I have placed a dropdown list in the edititemtemplate of a formview control and followed specific MSDN instructions on how to bind the list source to a separate SQL lookup data source but have the formview bound to the main data source. If I set the selecteditem value to bind to the formview control I always get the following error:
'DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items.

This is my asp:

<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" 
DataSourceID="SqlDataSource2" DataTextField="Type" 
DataValueField="Type"
selectedvalue='<%# Bind("ServiceProviderType") %>'>
</asp:DropDownList>

I have read over 50 posts on this and got nowhere - HELP!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by garyhumf
0

No I haven't seen thi sbut I have seen similar articles with the same instructions. Specifically its the "SelectedValue='<%# Bind("Category") %>' runat="server" >" line that just does not work. I ended up solving the problem by coding the update as follows:

Protected Sub Formview1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles FormView1.ItemUpdating
        e.NewValues("ServiceProviderType") = CType(FormView1.FindControl("dropdownlist1"), DropDownList).SelectedValue
    End Sub

Edited by peter_budo: Correcting closing tag

This question has already been answered. 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.