I have a gridview with column that have droplist when enter edit mode:
<asp:TemplateField HeaderText="genre" SortExpression="genre">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="name">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("genre") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Now i want to take it to UpdateParameters of SqlDataSource:
<UpdateParameters>
<asp:ControlParameter ControlID="DropDownList2" Type="string" PropertyName="SelectedValue" Name="genre" />
</UpdateParameters>
But when i pressed he give me Error msg
Could not find control 'DropDownList2' in ControlParameter 'genre'.
Any idea why?
DropDownList2 is a nested control located under the Grid; therefore, your SqlDataSource control does not have visibility at all of the DropDownList2.
You could try assigning the value on the code behind by using the Updating event:
Note: You will need to use FindControl(“DropDownList2”) in GetDropDownListValue()