Using a dropdownlist control inside a formview

iwaniwan

New Member
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 Exception Details: System.InvalidOperationException: Could not find control 'ddlCategory' in ControlParameter 'categoryId'.The Dropdownlist inside a formview.\[code\] <asp:DropDownList ID="ddlCategory" DataSourceID="ObjectDataSourceCategory" DataTextField="NAME" DataValueField="ID" runat="server" />\[/code\]The SQL Data Source \[code\] <asp:ObjectDataSource ID="sqlDataSourceItem" TypeName="Item" runat="server" SelectMethod="getItem" InsertMethod="insertItem" UpdateMethod="updateItem"> <SelectParameters> <asp:QueryStringParameter QueryStringField="id" Name="id" /> </SelectParameters> <InsertParameters> <asp:ControlParameter ControlID="ddlCategory" Name="categoryId" PropertyName="selectedValue" /> </InsertParameters> </asp:ObjectDataSource>\[/code\]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.\[code\] <asp:ControlParameter ControlID="ctl00$main$frmViewItem$ddlCategory" Name="categoryId" PropertyName="selectedValue" />\[/code\]
 
Back
Top