If you have used SqlDataSource control with the GridView, FormView or the DetailsView and updating the data in the database using the UpdateCommand and UpdateParameters of the SqlDataSource control then you might be familiar with this error. The error "Could not find control 'xxx' in ControlParameter 'xxx'" is thrown when the ASP.NET is not able to find the requested control defined in the Update ControlParameters.
Check out the code below which will throw the above exception:
<
asp:DetailsView DataKeyNames="UserID" AllowPaging="true" ID="dvUsers" runat="server" DataSourceID="SqlDataSource1" AutoGenerateRows="false"> <Fields>
<asp:BoundField HeaderText="UserID" DataField="UserID" />
<asp:TemplateField HeaderText="User Name">
<EditItemTemplate>
<asp:TextBox ID="txtUserName" runat="server" Text = '<%# GetUserName() %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No of Pets">
<ItemTemplate>
<asp:Label ID="lblNoOfPets" runat="server" Text = '<%# Eval("NoOfPets") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="SELECT * FROM Users" ConnectionString='<%$ ConnectionStrings:ConnectionString %>'
UpdateCommand="UPDATE Users SET UserName = @UserName, DateCreated = GETDATE() WHERE UserID = @UserID">
<UpdateParameters>
<asp:ControlParameter ControlID = "txtUserName" Name="UserName" Type="String" PropertyName="Text" />
<asp:Parameter Name="UserID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
And now, here is the code which does not throw the error. All you need to do is to refer to your control with its full name.
<UpdateParameters> <asp:ControlParameter ControlID = "gvUsers$txtUserName" Name="UserName" Type="String" PropertyName="Text" /> <asp:Parameter Name="UserID" Type="Int32" /> </UpdateParameters> You can easily find the control's full name when you open the page in the browser and you can see the control simply view source and you will see it.
Hope this tip helps!