In the code at the end of this post, the dropdownlist and the textboxes are used to supply values for an update command associated with a sqldatasource. When the update command runs, it returns the following error:

*****************************************************
Could not find control 'ddlTitle' in ControlParameter 'Title'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Could not find control 'ddlTitle' in ControlParameter 'Title'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidOperationException: Could not find control 'ddlTitle' in ControlParameter 'Title'.]
System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +1753150
System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +47
System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +114
System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +41
System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +264
System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +117
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
System.Web.UI.WebControls.FormView.HandleUpdate(String commandArg, Boolean causesValidation) +835
System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +509
System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +113
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
***************************************************

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="MyProfile.aspx.vb" Inherits="MyProfile" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
    <asp:FormView ID="frmProfile" DataSourceID="sdsProfile" DefaultMode="Edit" runat="server">
        <HeaderTemplate>
            <table cellpadding="3" cellspacing="0" border="0" width="100%" align="center">
                <tr><td colspan="4" align="center"><p class="titleMajor">Editing My Profile</p><br /></td></tr>
        </HeaderTemplate>
        <EditItemTemplate>
             <tr>
                <td class="formLabel" align="right"><asp:Label ID="Label1" ForeColor="Black" Text="Title" AssociatedControlID="ddlTitle" runat="server" /></td>
                <td>
                    <asp:DropDownList ID="ddlTitle" CssClass="formEntry" Width="95%" runat="server" >
                        <asp:ListItem Text="<Select title>" Value="" />
                        <asp:ListItem Text="Dr." Value="Dr." />
                        <asp:ListItem Text="Mr." Value="Mr." />
                        <asp:ListItem Text="Mrs." Value="Mrs." />
                        <asp:ListItem Text="Ms." Value="Ms." />
                        <asp:ListItem Text="Prof." Value="Prof." />
                    </asp:DropDownList> 
                    <br /><br />
                </td>
              </tr>
              <tr class="subBar">
                <td width="15%" class="formLabel" align="right"><font color=red>*</font><asp:Label ID="lblGivenName" ForeColor="Black" Text="Given Name" AssociatedControlID="txtGivenName" runat="server" />
                    <br /><asp:Label ID="Label11" Text=" (First Name)" runat="server" /></td>
                <td width="35%"><asp:TextBox ID="txtGivenName" runat="server" Text="<%# Bind('GivenName') %>" MaxLength="40" CssClass="formEntry" Width="95%" />
                                <asp:RequiredFieldValidator ID="reqGivenName" ControlToValidate="txtGivenName" Text="Enter your given name (first name)" runat="server" />
                </td>
                <td width="15%" class="formLabel" align="right"><font color=red>*</font><asp:Label ID="lblSurname" ForeColor="Black" Text="Surname" AssociatedControlID="txtSurName" runat="server" />               
                    <br /><asp:Label ID="Label2" Text=" (Last Name)" runat="server" /></td>
                <td width="35%"><asp:TextBox ID="txtSurName" runat="server" Text="<%# Bind('SurName') %>" MaxLength="40" CssClass="formEntry" Width="95%" />
                                <asp:RequiredFieldValidator ID="reqSurName" ControlToValidate="txtSurName" Text="Enter your surname (last name)" runat="server" />
                </td>
              </tr>
              <tr>
                <td width="15%" class="formLabel" align="right"><font color=red>*</font><asp:Label ID="lblAffiliation" ForeColor="Black" Text="Affiliation" AssociatedControlID="txtAffiliation" runat="server" /></td>
                <td width="35%"><asp:TextBox ID="txtAffiliation" runat="server" Text="<%# Bind('Affiliation') %>" MaxLength="150" CssClass="formEntry" Width="95%" />
                                <asp:RequiredFieldValidator ID="Affiliation" ControlToValidate="txtAffiliation" Text="Enter your affiliation" runat="server" />
                </td>
                <td width="15%" class="formLabel" align="right"><asp:Label ID="lblDepartment" ForeColor="Black" Text="Department" AssociatedControlID="txtDepartment" runat="server" /></td>
                <td width="35%"><asp:TextBox ID="txtDepartment" runat="server" Text="<%# Bind('Department') %>" MaxLength="150" CssClass="formEntry" Width="95%" /><br /><br />
                </td>
              </tr>
              <tr>
                <td width="15%" class="formLabel" align="right"><font color=red>*</font><asp:Label ID="lblAddress" ForeColor="Black" Text="Address" AssociatedControlID="txtAddress" runat="server" /></td>
                <td colspan="3"><asp:TextBox ID="txtAddress" runat="server" Text="<%# Bind('Address') %>" MaxLength="150" CssClass="formEntry" Width="98.75%" />
                                <asp:RequiredFieldValidator ID="reqAddress" ControlToValidate="txtAddress" Text="Enter your address" runat="server" />
                </td>
              </tr>
              <tr class="subBar">
                <td width="15%" class="formLabel" align="right"><font color=red>*</font><asp:Label ID="lblCity" ForeColor="Black" Text="City" AssociatedControlID="txtCity" runat="server" /></td>
                <td width="35%"><asp:TextBox ID="txtCity" runat="server" Text="<%# Bind('City') %>" MaxLength="20" CssClass="formEntry" Width="95%" />
                                <asp:RequiredFieldValidator ID="reqCity" ControlToValidate="txtCity" Text="Enter your city" runat="server" />
                </td>
                <td width="15%" class="formLabel" align="right"><asp:Label ID="lblStateProvince" ForeColor="Black" Text="State/Province" AssociatedControlID="txtStateProvince" runat="server" /></td>
                <td width="35%"><asp:TextBox ID="txtStateProvince" runat="server" Text="<%# Bind('StateProvince') %>" MaxLength="20" CssClass="formEntry" Width="95%" /><br /><br /></td>
              </tr>
              <tr class="subBar">
                <td width="15%" valign="middle" class="formLabel" align="right"><asp:Label ID="lblPostalCode"  ForeColor="Black" Text="Postal Code" AssociatedControlID="txtPostalCode" runat="server" /></td>
                <td width="35%" valign="middle"><asp:TextBox ID="txtPostalCode" runat="server" Text="<%# Bind('PostalCode') %>" MaxLength="20" CssClass="formEntry" Width="95%" /><br /><br /></td>
                <td width="15%" valign="middle" class="formLabel" align="right"><font color=red>*</font><asp:Label ID="lblCountry" ForeColor="Black" Text="Country" AssociatedControlID="txtCountry" runat="server" /></td>
                <td width="35%" valign="middle"><asp:TextBox ID="txtCountry" runat="server" Text="<%# Bind('Country') %>" MaxLength="20" CssClass="formEntry" Width="95%" />
                                <asp:RequiredFieldValidator ID="reqCountry" ControlToValidate="txtCountry" Text="Enter your country" runat="server" />
                </td>
              </tr>
              <tr>
                <td width="15%" class="formLabel" align="right"><font color=red>*</font><asp:Label ID="lblEmail" ForeColor="Black" Text="Email" AssociatedControlID="txtEmail" runat="server" /></td>
                <td colspan="3" align="left"><asp:TextBox ID="txtEmail" runat="server" Text="<%# Bind('Email') %>" MaxLength="150" CssClass="formEntry" Width="98.75%" />
                                <asp:RegularExpressionValidator id="regEmail" ControlToValidate="txtEmail" Text="(Not a valid email address)" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Runat="server" /> 
                                <asp:RequiredFieldValidator ID="reqEmail" ControlToValidate="txtEmail" Text="Enter your email address" CssClass="formEntry" runat="server" />
                </td>
              </tr>
              <tr class="subBar">
                <td width="15%" class="formLabel" align="right"><asp:Label ID="lblTelephone" ForeColor="Black" Text="Telephone" AssociatedControlID="txtTelephone" runat="server" /></td>
                <td width="35%"><asp:TextBox ID="txtTelephone" runat="server" Text="<%# Bind('Telephone') %>" MaxLength="20" CssClass="formEntry" Width="95%" /></td>
                <td width="15%" class="formLabel" align="right"><asp:Label ID="lblFax" ForeColor="Black" Text="Fax" AssociatedControlID="txtFax" runat="server" /></td>
                <td width="35%"><asp:TextBox ID="txtFax" runat="server" MaxLength="20" CssClass="formEntry" Width="95%" /></td>
              </tr>
              <tr>
                <td width="15%" valign="top" class="formLabel" align="right"><br /><asp:Label ID="lblBio" ForeColor="Black" Text="Bio" AssociatedControlID="txtBio"  runat="server" /></td>
                <td colspan="3"><br /><asp:TextBox ID="txtBio" TextMode="MultiLine" Height="144px" Wrap="True" runat="server" Text="<%# Bind('Bio') %>" CssClass="formEntry" Width="98.75%" />
                </td>
              </tr>
              <tr>
                <td colspan="4" align="center"><br /><asp:Button ID="btnUpdate" Text="Update" CommandName="Update" runat="server" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="btnCancel" Text="Cancel" CommandName="Cancel" runat="server" /></td>
              </tr>

        </EditItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
        <EmptyDataTemplate>
              <tr>
                <td colspan="4" class="formLabel" align="center"><asp:Label ID="lblNoData" ForeColor="Black" Text="No data found." runat="server" /></td>
              </tr>
        </EmptyDataTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="sdsProfile" runat="server" 
            ConnectionString="<%$ ConnectionStrings:JournalMgmtConnectionString %>"
            ProviderName="<%$ ConnectionStrings:JournalMgmtConnectionString.ProviderName %>"
            SelectCommand="SELECT Title, GivenName, Surname, Affiliation, Department, Address, City, StateProvince, PostalCode, Country, Email, Telephone, Fax, Bio FROM Journal_ReviewersEtAl
                WHERE UserName = @UserName"
            UpdateCommand="Update Journal_ReviewersEtAl Set Title = @Title, GivenName = @GivenName, Surname = @Surname, Affiliation = @Affiliation, Department = @Department, Address = @Address, 
                City = @City, StateProvince = @StateProvince, PostalCode = @PostalCode, Country = @Country, Email = @Email, Telephone = @Telephone, Fax = @Fax, Bio = @Bio 
                WHERE UserName = @UserName">
            <SelectParameters>
                <asp:Parameter Name="UserName" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:ControlParameter Name="Title" Type="String" ControlID="ddlTitle" PropertyName="SelectedValue" />
                <asp:ControlParameter Name="GivenName" type="String" ControlID="txtGivenName"/>
                <asp:ControlParameter Name="Surname" type="String" ControlID="txtSurname"/>
                <asp:ControlParameter Name="Affiliation" type="String" ControlID="txtAffiliation"/>
                <asp:ControlParameter Name="Department" Type="String" ControlID="txtDepartment" />
                <asp:ControlParameter Name="Address" Type="String" ControlID="txtAddress" />
                <asp:ControlParameter Name="City" Type="String" ControlID="txtCity" />
                <asp:ControlParameter Name="StateProvince" type="String" ControlID="txtStateProvince"/>
                <asp:ControlParameter Name="PostalCode" type="String" ControlID="txtPostalCode"/>
                <asp:ControlParameter Name="Country" type="String" ControlID="txtCountry"/>
                <asp:ControlParameter Name="Email" type="String" ControlID="txtEmail"/>
                <asp:ControlParameter Name="Telephone" type="String" ControlID="txtTelephone"/>
                <asp:ControlParameter Name="Fax" type="String" ControlID="txtFax"/>
                <asp:ControlParameter Name="Bio" type="String" ControlID="txtBio"/>
                <asp:ControlParameter Name="UserName" Type="String" />
            </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder4" Runat="Server">
</asp:Content>

The reason why your are experiencing this error is because all of the controls are not a part of the form, they are part of the EditItemTemplate in the FormView control. This means that they are not accessable to the SqlDataSource control. The Bind() method that you are using should be all you need. Check out this page on MSDN: http://msdn.microsoft.com/en-us/library/ms178366.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.