• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1833
  • Last Modified:

Update database using SQLDatasource with Stored procedure & Gridview

I've got a Gridview using a SQL Datasource and I have an update stored procedure.  I'm getting an error when I click the "Update" on a row.  Then error is:
Could not find control 'fID' in ControlParameter 'featureID'.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:myDB1 %>"
                    SelectCommand="QryFeatures" SelectCommandType="StoredProcedure" 
                    UpdateCommandType="StoredProcedure" UpdateCommand="UptFeature"
                    DeleteCommandType="storedProcedure" DeleteCommand="DelFeature">
                    <UpdateParameters>
                        <asp:ControlParameter ControlID="fID"  Name="featureID" PropertyName="text"/>
                       <asp:ControlParameter ControlID="fText"  Name="featureText" PropertyName="text"/>
                    </UpdateParameters>
                </asp:SqlDataSource>
<asp:GridView ID="gvFeatures" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" DataKeyNames="featureID">
                    <Columns>
                        <asp:BoundField DataField="featureID" />
                        
                        <asp:TemplateField HeaderText="Feature">
                            <ItemStyle Width="200px" />
                            <ItemTemplate>
                                <asp:Label ID="lblFeature" runat="server" Text='<%# Eval("featureText") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="fText" runat="server" Text='<%# Bind("featureText") %>'></asp:TextBox>
                            </EditItemTemplate>
                        </asp:TemplateField>
			 <asp:TemplateField HeaderText="Edit">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" Text="Edit" CommandName="Edit" CausesValidation="false" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:LinkButton ID="LinkButton3" runat="server" Text="Update" CommandName="Update"
                                    CausesValidation="true" />
                                <asp:LinkButton ID="LinkButton4" runat="server" Text="Cancel" CommandName="Cancel"
                                    CausesValidation="false" />
                            </EditItemTemplate>
                        </asp:TemplateField>
		</Columns>
</asp:Gridview>

Open in new window

0
robnhood00
Asked:
robnhood00
1 Solution
 
strickddCommented:
It's because you are using a ControlParameter bound to a control with ID="fID". Since I don't see that control anywhere in the Edit template, i'm assuming you aren't actually setting the value.

You can also look into setting up the datakeys in the gridview so it automatically passes the primary key value to an update or delete.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now