for the past days i've been trying to find a solution for my problem but so far i couldn't. I Have a Gridview that in edit mode, one of the fields have a DropDownList of people that is populated by a Select that uses two other fields of that row (State and City). I tried everything i found on the web about it and i couldn't make it work. Can you help me please? Code below
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
DataKeyNames="id,Municipio,UF" DataSourceID="SqlDataSource5">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
...stuff...
<asp:TemplateField HeaderText="UF" SortExpression="UF">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("UF") %>'>
</asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("UF") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Municipio" SortExpression="Municipio">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Municipio") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Municipio") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="People" SortExpression="People">
<ItemTemplate>
<asp:Label ID="LbPeople" runat="server" Text='<%# Bind("Cultura") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DdlPeople" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSourcePeopleEdit" DataTextField="People"
DataValueField="People">
</asp:DropDownList>
<asp:HiddenField ID="Hidden1" Value='<%# Bind("Municipio") %>' runat="server"/>
<asp:HiddenField ID="Hidden2" Value='<%# Bind("UF") %>' runat="server"/>
<asp:SqlDataSource ID="SqlDataSourcePeopleEdit" runat="server"
ConnectionString="<%$ ConnectionStrings:dbdb %>"
ProviderName="<%$ ConnectionStrings:somar.ProviderName %>"
SelectCommand="SELECT People FROM Table_People WHERE (Cidade = @Municipio) AND (UF = @UF)"
CancelSelectOnNullParameter="false">
<SelectParameters>
<asp:ControlParameter ControlID="Hidden1" Name="Municipio" PropertyName="Value" Type="String" />
<asp:ControlParameter ControlID="Hidden2" Name="UF" PropertyName="Value" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
</asp:TemplateField>
...stuff...
</asp:GridView>
What am i doing wrong?
UPDATE when i click edit, the dropdownlist does not load values. And if i set the property CancelSelectOnNullParameter="false" on SqlDataSource it shows 'Must declare scalar variable @xxx' I have inspected the hiddenfields and they have values loaded, so the problem is the controlparameter taht does not get the value from it