Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
or 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.NET
<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?

What I have tried:

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
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900