【问题标题】:DropdownList Selected Value as Parameter for another DropdownListDropdownList 选定值作为另一个 DropdownList 的参数
【发布时间】:2015-12-27 11:38:09
【问题描述】:

我在这里尝试实现我的目标有点困难,

我有两个下拉菜单,我希望能够根据 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>

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 对不起,这是我的错字,选择中的位置已经
    • 和 asp:SqlDataSource 和 asp:DropDownLists 的 ID 在代码 sn-ps(SqlDataSource1 和 SqlDataSource2)中是不同的。这也是笔误?
    • 来自问题的代码 sn-ps:asp:SqlDataSource has ID="SqlDataSource2" 而所有 asp:DropDownList reference DataSource="SqlDataSource1"
    猜你喜欢
    • 2020-03-03
    • 1970-01-01
    • 2016-04-19
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    相关资源
    最近更新 更多