【问题标题】:Dependent drop downs in grid view网格视图中的相关下拉列表
【发布时间】:2016-10-06 04:22:49
【问题描述】:

我有两个下拉国家和大学是从属下拉。如果国家/地区将选择将 Countryd 传递给大学表 countryid,则大学列表应出现在大学下拉列表中。

下面是 Gridview 中的 Country Drop 淹没列表

<asp:DropDownList ID="ddl_Country" runat="server" AppendDataBoundItems="true" Width="60px"
DataSourceID="SqlDataSource6" DataTextField="Country" DataValueField="CountryID"
  AutoPostBack="True" OnSelectedIndexChanged="ddl_Country_SelectedIndexChanged">

下面是 Gridview 中的大学下拉列表。

<asp:DropDownList ID="ddl_University" runat="server" AppendDataBoundItems="true" Width="60px"
  DataSourceID="SqlDataSource7" DataTextField="University" DataValueField="University">

我的两个数据源:

 <asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
 SelectCommand="Get_Country" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
  <asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="Get_University" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

下面是我的两个存储过程

国家存储过程:

 ALTER procedure [dbo].[Get_Country]
 as
 select Country,CountryId from Table_LKP_Country order by Country ASC

大学存储过程:

 ALTER procedure [dbo].[Get_University]
 as
 select University,CountryId from Table_LKP_University order by University ASC

我想将 CountryID 传递给 LKP 大学表 countryid 并根据 countryid 在下拉列表中填写大学列表。我不知道如何使用国家选择索引或使用两个 sqldatasouce 来实现。

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    试试这个

    <asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
        SelectCommand="Get_University" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
    
    <SelectParameters>
         <asp:ControlParameter ControlID="ddl_Country" PropertyName="SelectedValue" Name="CountryID" Type="Int32" DefaultValue="0" />
    </SelectParameters>
    

    ALTER procedure [dbo].[Get_University]
     as
     select University,CountryId from Table_LKP_University where CountryId=@CountryID order by University ASC
    

    【讨论】:

    • 我必须将它添加到 SqlDataSource7 中。 @Annalaxmi
    • @zahed 是的,试试这个你的 sqldatasource7
    • 我更改了 lkp 大学程序并通过 countryid 如下:ALTER 程序 [dbo].[Get_University] (@CountryId int) 从 Table_LKP_University 中选择 University,CountryId where CountryId=@CountryId order by University ASC。
    • 我收到此错误:在 ControlParameter 'CountryId' 中找不到控件'ddl_Country'。 @Annalaxmi
    • 检查我的国家下拉列表: 出现错误:在 ControlParameter 'CountryId' 中找不到控件'ddl_Country'。
    猜你喜欢
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    相关资源
    最近更新 更多