How to use a dropdown list in the EditItemTemplate of an asp.net web forms application using c#?

Hello Experts.

I am attempting to use a dropdown list in the EditItemTemplate of a FormView.  Unfortunately I keep getting an error.

The source for the dropdown list is:
<asp:SqlDataSource 
                    ID="sdc_vendor_st_dir_ddl" 
                    runat="server" 
                    ConnectionString="<%$ ConnectionStrings:idrfConnectionString %>" 
                    SelectCommand="SELECT st_dir_id_pk, st_dir, st_dir_active_yn FROM [tbl_st_dir_list] WHERE st_dir_active_yn=3">
                </asp:SqlDataSource>

Open in new window


The dropdown list and accompanying label are:
<div class="col-md-3">
     <strong>Direction:</strong><br />
                    <asp:DropDownList 
                        ID="vendor_st_dir_ddl" 
                        runat="server" 
                        DataSourceID="sdc_vendor_st_dir_ddl" 
                        DataTextField="st_dir" 
                        DataValueField="st_dir_id_pk"
                        AppendDataBoundItems="true"
                        SelectedValue='<%# Bind("st_dir") %>'>
                    </asp:DropDownList>      

                    <asp:Label ID="vendor_st_dir_ddl_lbl" Visible="false" runat="server" Text='<%# Eval("st_dir") %>' />

Open in new window


The source for the list items of the dropdown field is the tbl_st_dir_list table.
The dropdown list updates the vendor_st_dir_list field in the tbl_vendor table.
The primary key of the value chosen from tbl_st_dir_list is stored in tbl_vendor.  

Unfortunately, I keep getting the following error when I click on the "update" button:

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

Here is the code for the entire page:
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <h2 class="pg_title"><%: Title %></h2>
    <%--Directions--%>
    <div>
    <h4 style="text-decoration: underline;">Directions:</h4>
    <p>Use this form to review and &#47; or edit data for vendors already in the IDR system.<br /><em>Hint: Enter a &quot&#37&quot to search all vendors.</em></p>
    Search for a vendor: <asp:TextBox ID="gv_frm_vendor_srch_txt" runat="server"></asp:TextBox>&nbsp&nbsp<asp:Button ID="btn_gv_frm_vendor_srch_txt" runat="server" Text="Search..." /><br /><br />
    </div>

    <%--Vendor GV--%>
    <asp:GridView 
        ID="gv_frm_vendor" 
        runat="server" 
        AllowPaging="True" 
        AllowSorting="True" 
        DataSourceID="sdc_gv_frm_vendor" 
        PageSize="5" 
        AutoGenerateColumns="False" 
        DataKeyNames="vendor_id_pk" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" >
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField AccessibleHeaderText="Vendor Identification" DataField="vendor_id_pk" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="vendor_id_pk" HeaderStyle-CssClass="gv_hdr_style" ItemStyle-CssClass="gv_item_style" >
<HeaderStyle CssClass="gv_hdr_style"></HeaderStyle>

<ItemStyle CssClass="gv_item_style"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField AccessibleHeaderText="Vendor Name" DataField="vendor_nm" HeaderText="Vendor" SortExpression="vendor_nm" HeaderStyle-CssClass="gv_hdr_style" >
<HeaderStyle CssClass="gv_hdr_style"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField AccessibleHeaderText="Street Direction" DataField="st_dir" HeaderText="Direction" SortExpression="st_dir" HeaderStyle-CssClass="gv_hdr_style" ItemStyle-CssClass="gv_item_style" >
<HeaderStyle CssClass="gv_hdr_style"></HeaderStyle>

<ItemStyle CssClass="gv_item_style"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField AccessibleHeaderText="Vendor Address" DataField="vendor_st_add" HeaderText="Address" SortExpression="vendor_st_add" HeaderStyle-CssClass="gv_hdr_style" >
<HeaderStyle CssClass="gv_hdr_style"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField AccessibleHeaderText="Street Type" DataField="st_type" HeaderText="Type" SortExpression="st_type" HeaderStyle-CssClass="gv_hdr_style" >
<HeaderStyle CssClass="gv_hdr_style"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField AccessibleHeaderText="Vendor City" DataField="vendor_city" HeaderText="City" SortExpression="vendor_city" HeaderStyle-CssClass="gv_hdr_style" >
<HeaderStyle CssClass="gv_hdr_style"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField AccessibleHeaderText="Vendor Zip Code" DataField="vendor_zip" HeaderText="Zip Code" SortExpression="vendor_zip" HeaderStyle-CssClass="gv_hdr_style" ItemStyle-CssClass="gv_item_style" >
<HeaderStyle CssClass="gv_hdr_style"></HeaderStyle>

<ItemStyle CssClass="gv_item_style"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField AccessibleHeaderText="Vendor Phone Number" DataField="vendor_prim_ph" HeaderText="Phone" SortExpression="vendor_prim_ph" HeaderStyle-CssClass="gv_hdr_style" >
<HeaderStyle CssClass="gv_hdr_style"></HeaderStyle>
            </asp:BoundField>
        </Columns>
        <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
        <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
        <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F7F7F7" />
        <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
        <SortedDescendingCellStyle BackColor="#E5E5E5" />
        <SortedDescendingHeaderStyle BackColor="#242121" />
    </asp:GridView><br />
  
    <%--SDC for GV--%>
    <asp:SqlDataSource ID="sdc_gv_frm_vendor" 
        runat="server" 
        ConnectionString="<%$ ConnectionStrings:idrfConnectionString %>" 
        SelectCommand="SELECT v.[vendor_id_pk], 
                v.[vendor_nm], 
                sdl.st_dir,
                v.[vendor_st_add], 
                stl.st_type,
                v.[vendor_city], 
                sl.[state],
                v.[vendor_zip], 
                v.[vendor_prim_ph] 
            FROM 
                [tbl_vendor] v

            LEFT JOIN [dbo].[tbl_st_dir_list] sdl
            ON v.vendor_st_dir_list = sdl.st_dir_id_pk
            LEFT JOIN [dbo].[tbl_st_type_list] stl
            ON v.vendor_st_type_list=stl.st_type_id_pk
            LEFT JOIN [dbo].[tbl_state_list] sl
            ON v.vendor_state_list=sl.state_id_pk
            
            WHERE ([vendor_nm] LIKE '%' + @vendor_nm + '%')
            
            ORDER BY v.vendor_nm">
        <SelectParameters>
            <asp:ControlParameter ControlID="gv_frm_vendor_srch_txt" Name="vendor_nm" PropertyName="Text" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    
    <%--Vendor FV--%>
    <asp:FormView ID="fv_frm_vendor" runat="server" DataKeyNames="vendor_id_pk" DataSourceID="sdc_fv_frm_vendor" RenderOuterTable="false">
        <EditItemTemplate>
            <div class="row">
                <div class="col-md-12">
                    <em>&#42;&#42;&#42;Mailing Address...</em>
                </div>
            </div>
            <div class="row">
                <div class="col-md-3">
                    <strong>ID:</strong><br />
                    <asp:Label ID="vendor_id_pkLabel1" runat="server" Text='<%# Eval("vendor_id_pk") %>' />
                </div>

                <div class="col-md-3">
                    <strong>Name:</strong><br />
                    <asp:TextBox ID="vendor_nmTextBox" runat="server" Text='<%# Bind("vendor_nm") %>' />
                </div>

                <%--SDC for Direction DDL--%>
                <asp:SqlDataSource 
                    ID="sdc_vendor_st_dir_ddl" 
                    runat="server" 
                    ConnectionString="<%$ ConnectionStrings:idrfConnectionString %>" 
                    SelectCommand="SELECT st_dir_id_pk, st_dir, st_dir_active_yn FROM [tbl_st_dir_list] WHERE st_dir_active_yn=3">
                </asp:SqlDataSource>    

                <div class="col-md-3">
                    <strong>Direction:</strong><br />
                    <asp:DropDownList 
                        ID="vendor_st_dir_ddl" 
                        runat="server" 
                        DataSourceID="sdc_vendor_st_dir_ddl" 
                        DataTextField="st_dir" 
                        DataValueField="st_dir_id_pk"
                        AppendDataBoundItems="true"
                        SelectedValue='<%# Bind("st_dir") %>'>
                    </asp:DropDownList>      
                    <asp:Label ID="vendor_st_dir_ddl_lbl" Visible="false" runat="server" Text='<%# Eval("st_dir") %>' />
                    <%--<asp:TextBox ID="st_dirTextBox" runat="server" Text='<%# Bind("st_dir") %>' />--%>
                </div>
                <%--End of Direction DDL--%>

                <div class="col-md-3">
                    <strong>Address:</strong><br />
                    <asp:TextBox ID="vendor_st_addTextBox" runat="server" Text='<%# Bind("vendor_st_add") %>' />
                </div>
            </div>

            <div class="row">
                <div class="col-md-3">
                    <strong>Type:</strong><br />
                    <asp:TextBox ID="st_typeTextBox" runat="server" Text='<%# Bind("st_type") %>' />
                </div>

                <div class="col-md-3">
                    <strong>City:</strong><br />
                    <asp:TextBox ID="vendor_cityTextBox" runat="server" Text='<%# Bind("vendor_city") %>' />
                </div>

                <div class="col-md-3">
                    <strong>State:</strong><br />
                    <asp:TextBox ID="stateTextBox" runat="server" Text='<%# Bind("state") %>' />
                </div>

                <div class="col-md-3">
                    <strong>Zip Code:</strong><br />
                    <asp:TextBox ID="vendor_zipTextBox" runat="server" Text='<%# Bind("vendor_zip") %>' />
                </div>
            </div>

            <div class="row">
                <div class="col-md-3">
                    <strong>Phone:</strong><br />
                    <asp:TextBox ID="vendor_prim_phTextBox" runat="server" Text='<%# Bind("vendor_prim_ph") %>' />
                </div>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <strong>Comments:</strong><br />
                    <asp:Label ID="vendor_cmntsLabel" runat="server" Text='<%# Bind("vendor_cmnts") %>' />
                </div>
            </div>

            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />&nbsp;
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>
        <InsertItemTemplate>
            vendor_nm:
            <asp:TextBox ID="vendor_nmTextBox" runat="server" Text='<%# Bind("vendor_nm") %>' />
            <br />
            st_dir:
            <asp:TextBox ID="st_dirTextBox" runat="server" Text='<%# Bind("st_dir") %>' />
            <br />
            vendor_st_add:
            <asp:TextBox ID="vendor_st_addTextBox" runat="server" Text='<%# Bind("vendor_st_add") %>' />
            <br />
            st_type:
            <asp:TextBox ID="st_typeTextBox" runat="server" Text='<%# Bind("st_type") %>' />
            <br />
            vendor_city:
            <asp:TextBox ID="vendor_cityTextBox" runat="server" Text='<%# Bind("vendor_city") %>' />
            <br />
            state:
            <asp:TextBox ID="stateTextBox" runat="server" Text='<%# Bind("state") %>' />
            <br />
            vendor_zip:
            <asp:TextBox ID="vendor_zipTextBox" runat="server" Text='<%# Bind("vendor_zip") %>' />
            <br />
            vendor_prim_ph:
            <asp:TextBox ID="vendor_prim_phTextBox" runat="server" Text='<%# Bind("vendor_prim_ph") %>' />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </InsertItemTemplate>
        <ItemTemplate>
            <div class="container-fluid">
                <div class="row" style="padding-bottom: 15px;">
                    <div class="col-md-3">
                        <strong>ID:</strong><br />
                        <asp:Label ID="vendor_id_pkLabel" runat="server" Text='<%# Eval("vendor_id_pk") %>' />
                    </div>
                    <div class="col-md-3">
                        <strong>Vendor:</strong><br />
                        <asp:Label ID="vendor_nmLabel" runat="server" Text='<%# Bind("vendor_nm") %>' />
                    </div>
                    <div class="col-md-3">
                        <strong>Road Direction:</strong><br />
                        <asp:Label ID="st_dirLabel" runat="server" Text='<%# Bind("st_dir") %>' />
                    </div>
                    <div class="col-md-3">
                        <strong>Address (Mailing):</strong><br />
                        <asp:Label ID="vendor_st_addLabel" runat="server" Text='<%# Bind("vendor_st_add") %>' />
                    </div>
                </div>
                <div class="row" style="padding-bottom: 15px;">
                    <div class="col-md-3">
                        <strong>Street Type:</strong><br />
                        <asp:Label ID="st_typeLabel" runat="server" Text='<%# Bind("st_type") %>' />
                    </div>

                    <div class="col-md-3">
                        <strong>City:</strong><br />
                        <asp:Label ID="vendor_cityLabel" runat="server" Text='<%# Bind("vendor_city") %>' />
                    </div>

                    <div class="col-md-3">
                        <strong>State:</strong><br />
                        <asp:Label ID="stateLabel" runat="server" Text='<%# Bind("state") %>' />
                    </div>

                    <div class="col-md-3">
                        <strong>Zip Code:</strong><br />
                        <asp:Label ID="vendor_zipLabel" runat="server" Text='<%# Bind("vendor_zip") %>' />
                    </div>
                </div>
                <div class="row" style="padding-bottom: 15px;">
                    <div class="col-md-3">
                        <strong>Phone:</strong><br />
                        <asp:Label ID="vendor_prim_phLabel" runat="server" Text='<%# Bind("vendor_prim_ph") %>' />
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <strong>Comments:</strong><br />
                        <asp:Label ID="vendor_cmntsLabel" runat="server" Text='<%# Bind("vendor_cmnts") %>' />
                    </div>
                </div>
            </div>

        </ItemTemplate>
    </asp:FormView>    

    <%--SDC for FV--%>
    <asp:SqlDataSource ID="sdc_fv_frm_vendor" runat="server" ConnectionString="<%$ ConnectionStrings:idrfConnectionString %>" SelectCommand="SELECT v.[vendor_id_pk], 
                v.[vendor_nm], 
                sdl.st_dir,
                v.[vendor_st_add], 
                stl.st_type,
                v.[vendor_city], 
                sl.[state],
                v.[vendor_zip], 
                v.[vendor_prim_ph],
                v.[vendor_cmnts]
            FROM 
                [tbl_vendor] v

            LEFT JOIN [dbo].[tbl_st_dir_list] sdl
            ON v.vendor_st_dir_list = sdl.st_dir_id_pk
            LEFT JOIN [dbo].[tbl_st_type_list] stl
            ON v.vendor_st_type_list=stl.st_type_id_pk
            LEFT JOIN [dbo].[tbl_state_list] sl
            ON v.vendor_state_list=sl.state_id_pk

            WHERE (v.vendor_id_pk = @vendor_id_pk)

            ORDER BY v.vendor_nm">
        <SelectParameters>
            <asp:ControlParameter ControlID="gv_frm_vendor" Name="vendor_id_pk" PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:SqlDataSource>

    <%--Edit FV--%>
    <div>
        <br />
        <span class="btn_style"><asp:Button ID="gv_frm_vendor_edit_bn" runat="server" Text="Edit..." OnClick="gv_frm_vendor_edit_bn_Click" /></span>
    </div>

</asp:Content>

Open in new window


Any help would be greatly appreciated.
ferguson_jeraldAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ferguson_jeraldAuthor Commented:
Please disregard.  I completely forgot to add the control to the ItemTemplate.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.