DropdownList选择的值作为另一个DropdownList的参数

时间:2015-09-29 20:35:43

标签: asp.net vb.net drop-down-menu

我在这里尝试完成目标时遇到了一些困难,

我有两个下拉菜单,我希望能够根据Dropdown_Parent中的选定值更改Dropdown_Objective中可用的值。这些下拉列表包含在TemplateField中,

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" PageSize="20" AutoGenerateColumns="False" DataKeyNames="VisitObjectiveKey" 
    onsorting="GridView1_Sorting" onpageindexchanging="GridView1_PageIndexChanging" Width="100%">
    <Columns>
        <asp:TemplateField HeaderText="ParentId" SortExpression="ParentId">
            <EditItemTemplate>
                <asp:DropDownList ID="UpdParentId" runat="server" Width="100%" SkinID="-1" CssClass="text ui-widget-content ui-corner-all" AppendDataBoundItems="true" DataSource="SqlDataSource1" DataTextField="ParentKeyDesc" DataValueField="ParentKey" >
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="ItemParentId" runat="server" Text='<%# Eval("ParentId") %>' ></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                <asp:DropDownList ID="InsParentId" runat="server" Width="100%" SkinID="-1" CssClass="text ui-widget-content ui-corner-all" AppendDataBoundItems="true" DataSource="SqlDataSource1" DataTextField="ParentKeyDesc" DataValueField="ParentKey" >
                </asp:DropDownList>
            </FooterTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="Objective" SortExpression="Objective">
            <EditItemTemplate>
                <asp:DropDownList ID="UpdObjective" runat="server" Width="100%" SkinID="-1" CssClass="text ui-widget-content ui-corner-all" AppendDataBoundItems="true" DataSource="SqlDataSource2" DataTextField="ObjectiveKeyDesc" DataValueField="ObjectiveKey" >
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="ItemObjective" runat="server" Text='<%# Eval("Objective") %>' ></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                <asp:DropDownList ID="InsObjective" runat="server" Width="100%" SkinID="-1" CssClass="text ui-widget-content ui-corner-all" AppendDataBoundItems="true" DataSource="SqlDataSource2" DataTextField="ObjectiveKeyDesc" DataValueField="ObjectiveKey" >
                </asp:DropDownList>
            </FooterTemplate>
        </asp:TemplateField>
    </Columns>

这是我尝试用于Dropdown_Objective的SqlDatesource,

<asp:SqlDataSource  ID="SqlDataSource2" 
                    runat="server" 
                    ConnectionString="<%$ ConnectionStrings:connectionString %>" 
                    SelectCommand="Select  ObjectiveKey, ObjectiveKeyDesc From T_Table Where ObjectiveKey = @ParentId">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="UpdParentId" 
                                              Name="ParentId" 
                                              PropertyName="SelectedValue"
                                              Type="String" />
                    </SelectParameters>
</asp:SqlDataSource>

任何想法,我做错了什么或如何实现我的目标?

1 个答案:

答案 0 :(得分:0)

应在SelectCommand中的asp:SqlDataSource属性内的查询中正确指定Where子句:         SelectCommand="Select ObjectiveKey, ObjectiveKeyDesc From T_Table ObjectiveKey = @ParentId">

试试这个:         SelectCommand="Select ObjectiveKey, ObjectiveKeyDesc From T_Table Where ObjectiveKey = @ParentId