Update SqlDataSource with value of DropDownList in EditTemplate on GridView

Discussion in 'ASP .Net Web Controls' started by ES, Jun 16, 2006.

  1. ES

    ES Guest

    Hello,
    I have a GridView with a DropDownList in the EditTemplate of one if my columns. I've got the drop down displaying the correct data, but need to do an update when the user changes the value and updates the row. I'm having difficulty getting the GridView's SqlDataSource UpdateParameter to see the DropDownList. Here is how it's set up:

    <asp:SqlDataSource runat="server" ID="SqlData1" ConnectionString="<%$ ConnectionStrings:myconn%>"
    SelectCommand="..."
    DeleteCommand="..."
    InsertCommand="...
    UpdateCommand="Update SalesRegion Set SalesRegionTypeID = @SalesRegionTypeID, SalesRegionCD = @SalesRegionCD, SalesRegion = @SalesRegion Where SalesRegionID = @SalesRegionID"

    <DeleteParameters>
    <asp:parameter Type="int32" Name="SalesRegionID" />
    </DeleteParameters>

    <UpdateParameters>
    <asp:parameter Type="int32" Name="SalesRegionID" />
    <asp:parameter Type="string" Name="SalesRegionCD" />
    <asp:parameter Type="string" Name="SalesRegion" />
    <asp:ControlParameter ControlID="dlRepType" Type="string" PropertyName="SelectedValue" Name="SalesRegionTypeID" />
    </UpdateParameters>

    </asp:SqlDataSource>

    <asp:GridView runat="server" ID="GV" DataSourceID="SqlData1" AutoGenerateColumns="false"
    DataKeyNames="SalesRegionID" HeaderStyle-CssClass="GVHead" RowStyle-CssClass="GVBody"
    EditRowStyle-CssClass="GVBodyEdit" CssClass="GV" AutoGenerateEditButton="true"
    >

    <Columns>
    ...
    <asp:TemplateField HeaderText="Rep Type">
    <ItemTemplate>
    <asp:Label Text='<%#Eval("SalesRegionType") %>' runat="server" />
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList ID="dlRepType" runat="server" DataSourceID="sdRepType" DataTextField="SalesRegionType"
    DataValueField="SalesRegionTypeID" SelectedValue='<%#Bind("SalesRegionTypeID") %>' />
    </EditItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    When update is clicked, the page throws
    System.InvalidOperationException: Could not find control 'dlRepType' in ControlParameter 'SalesRegionTypeID'.

    Any idea how to link this drop down to the update?

    Thanks,

    EE
     
    ES, Jun 16, 2006
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yan Wang

    DropdownList in EditTemplate

    Yan Wang, May 23, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,510
    Natty Gur
    May 24, 2004
  2. Krish

    EditTemplate - Dropdownlist

    Krish, Sep 21, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    661
    Krish
    Sep 21, 2005
  3. Jan
    Replies:
    2
    Views:
    834
  4. Savvoulidis Iordanis
    Replies:
    0
    Views:
    363
    Savvoulidis Iordanis
    Aug 15, 2008
  5. Vaughn Haybittle
    Replies:
    0
    Views:
    1,034
    Vaughn Haybittle
    Apr 2, 2007
  6. Rickey Whitworth

    Getting the ClientID of a control in a GridView EditTemplate

    Rickey Whitworth, Nov 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    624
    Rickey Whitworth
    Nov 10, 2005
  7. theWizard1

    Gridview Headers for ItemTemplate and EditTemplate

    theWizard1, Sep 15, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    952
    theWizard1
    Sep 15, 2006
  8. Joe Reiss

    Formview EditTemplate Dropdownlist

    Joe Reiss, Feb 20, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    251
    Joe Reiss
    Feb 20, 2007
Loading...