title: Using a dropdownlist control inside a formview
body: <p>I am new to asp.net and i have a problem using a dropdownlist control inside a formview and passing its value to the related sqldatasource. When i use the code below i get the following exception </p>
  
  <p><strong>Exception Details: System.InvalidOperationException: Could not find control 'ddlCategory' in ControlParameter 'categoryId'.</strong></p>
  
  <p><strong>The Dropdownlist inside a formview.</strong></p>
  
  <pre><code>      &lt;asp:DropDownList ID="ddlCategory" DataSourceID="ObjectDataSourceCategory" DataTextField="NAME" DataValueField="ID" runat="server" /&gt;
  </code></pre>
  
  <p><strong>The SQL Data Source</strong> </p>
  
  <pre><code>     &lt;asp:ObjectDataSource ID="sqlDataSourceItem" TypeName="Item" runat="server"
        SelectMethod="getItem"
        InsertMethod="insertItem"
        UpdateMethod="updateItem"&gt;
       &lt;SelectParameters&gt;
          &lt;asp:QueryStringParameter QueryStringField="id" Name="id" /&gt;
       &lt;/SelectParameters&gt;
       &lt;InsertParameters&gt;
          &lt;asp:ControlParameter ControlID="ddlCategory" Name="categoryId" PropertyName="selectedValue" /&gt;
       &lt;/InsertParameters&gt;
       &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p>And i have found the solution to this problem. I have changed the ID of the DDL in the control parameter. It works like below since this is the final generated id of that control. But i think there must be an easier and better way. Any help would be appriciated.</p>
  
  <pre><code>    &lt;asp:ControlParameter ControlID="ctl00$main$frmViewItem$ddlCategory" Name="categoryId" PropertyName="selectedValue" /&gt;
  </code></pre>