I'm trying to get value from DropDownList as a parameter for SQL query. I have a GridView and SqlDataSource. And I can't reach DropDownList ("DDLName") inside the GridView. When "DDLName" is outside the GridView, everything is working, but when I put It inside, I got an error which says that can't find "DDLName". I want to do this in .aspx. I've seen a lots of tips with using "$ but I was trying to use"GridView1$DDLName" and It's not working.
There is my code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource2" AutoGenerateEditButton="True" ShowFooter="True">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="firstname" HeaderText="firstname" SortExpression="firstname" />
<asp:BoundField DataField="lastname" HeaderText="lastname" SortExpression="lastname" />
<asp:TemplateField HeaderText="city">
<ItemTemplate>
<asp:Label ID = "LabelName" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID = "DDLName" runat="server" DataSourceID="DDLSource" DataTextField="name" ClientIDMode="Static"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="DDLSource" runat="server" ConnectionString="<%$ ConnectionStrings:MBase1ConnectionString %>" SelectCommand="SELECT [name] FROM [cities]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MBase1ConnectionString %>" SelectCommand="users_select_all_city" SelectCommandType="StoredProcedure" UpdateCommand="users_update_city" UpdateCommandType="StoredProcedure" DeleteCommand="users_delete" DeleteCommandType="StoredProcedure" InsertCommand="users_add" InsertCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="firstName" Type="String" />
<asp:Parameter Name="lastName" Type="String" />
<asp:Parameter Name="name" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="firstName" Type="String" />
<asp:Parameter Name="lastName" Type="String" />
<asp:ControlParameter ControlId="DDLName" Name="name" PropertyName="SelectedValue" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>