Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ASP:Repeater内使用SqlDataSource FilterExpression连接2个DropDownList_C#_Asp.net_Drop Down Menu_Repeater_Sqldatasource - Fatal编程技术网

C# 在ASP:Repeater内使用SqlDataSource FilterExpression连接2个DropDownList

C# 在ASP:Repeater内使用SqlDataSource FilterExpression连接2个DropDownList,c#,asp.net,drop-down-menu,repeater,sqldatasource,C#,Asp.net,Drop Down Menu,Repeater,Sqldatasource,在中继器行中使用2个下拉列表如何使用第一个列表作为第二个的过滤器 中继器的布局很简单:[category\u dropDown][item\u dropDown][add\u button] 问题是我无法连接两个下拉控件。SqlDataSource ControlParameter找不到要调用的ControlID(由repeater重命名的控件)。将ControlID值更改为“itemRepeater$dropDownCategory”显然没有帮助。如何将这些下拉列表成对绑定 主要是想知道是否有

在中继器行中使用2个下拉列表如何使用第一个列表作为第二个的过滤器

中继器的布局很简单:
[category\u dropDown][item\u dropDown][add\u button]

问题是我无法连接两个下拉控件。SqlDataSource ControlParameter找不到要调用的ControlID(由repeater重命名的控件)。将ControlID值更改为“itemRepeater$dropDownCategory”显然没有帮助。如何将这些下拉列表成对绑定

主要是想知道是否有标记代码解决方案,因为代码隐藏解决方案更容易实现

<asp:Repeater ID="itemRepeater" runat="server" OnItemCommand="itemRepeater_ItemCommand" onitemdatabound="itemRepeater_ItemDataBound">
    <HeaderTemplate>
        <table>
        <tr>
            <td>Category</td>
            <td>Item</td>
            <td></td>
        </tr>
    </HeaderTemplate>
    <ItemTemplate>        
        <tr>
            <td><asp:DropDownList ID="dropDownCategory" runat="server" DataSourceID="SqlDataSourceCategory" DataTextField="Category" 
                DataValueField="ID_cat" SelectedValue='<%# DataBinder.Eval(Container.DataItem,"Category") %>' AppendDataBoundItems="true">                    
                <asp:ListItem Value="%" Text="Pick category" Selected="True" />
                </asp:DropDownList></td>
            <td><asp:DropDownList ID="dropDownItem" runat="server" DataSourceID="SqlDataSourceItem" DataTextField="Item" 
                DataValueField="ID_item" SelectedValue='<%# DataBinder.Eval(Container.DataItem,"Item") %>' AppendDataBoundItems="true">
                <asp:ListItem Value="%" Text="Pick item" Selected="True"  />
                </asp:DropDownList></td>   
            <td><asp:Button ID="repeatedButton" runat="server" CommandName='<%# DataBinder.Eval(Container.DataItem, "Button") %>' Text='<%# DataBinder.Eval(Container.DataItem, "Button") %>' /></td>             
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>


<asp:SqlDataSource ID="SqlDataSourceCategory" runat="server" ConnectionString="..." 
    SelectCommand="SELECT [Category], [ID_cat] FROM [Categories]">
</asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSourceItems" runat="server" ConnectionString="..." 
    SelectCommand="SELECT [ID_item],[Item] FROM [Items]"  FilterExpression="WHERE [ID_cat] = @ID_cat" >
    <FilterParameters>
        <asp:ControlParameter Name="ID_cat" ControlID="dropDownCategory" PropertyName="SelectedValue" />
    </FilterParameters>
</asp:SqlDataSource>    

类别
项目
上面的ControlID绑定显然是错误的,因为SqlDataSourceItems无法在ItemTemplate中找到名为“dropDownCategory”的ControlID,并引发已知异常:无法在ControlParameter“ID\u cat”中找到控件“dropDownCategory”


提前感谢您的建议。

您好,以下链接将为您提供窍门:

e、 g:像这样的:

 DropDownList ddlcity = (DropDownList)grow.FindControl("ddlcity"); // To get the value of dropdown

        cmd.Parameters.Add("@city", ddlcity.SelectedItem.ToString());  // This will add selected item to database

谢谢这是有用的,但仍然无法使其发挥作用。。若它只是静态网格上的级联下拉列表,那个就并没有问题,但由于它们是动态添加的,所以我在多个场景中不断遇到许多不同的错误。