在ControlParameter 'y'中找不到控件'x'。

5

我正在尝试使用下拉列表过滤我的列表视图结果。

我已经修改了数据源的选择查询,如下所示...

列表视图:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/ASPNetDB.mdb" 
        SelectCommand="SELECT * FROM [tblNames] WHERE Surnames=@Surnames">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="Surnames" 
                PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:AccessDataSource>

下拉列表:
<asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="AccessDataSource2" DataTextField="Genre" 
        DataValueField="NameID" AppendDataBoundItems="true">
            <asp:ListItem Value="" Selected ="True" >All Surnames</asp:ListItem>
</asp:DropDownList>

    <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
        DataFile="~/App_Data/ASPNetDB.mdb" SelectCommand="SELECT * FROM [tblSurnames]">
    </asp:AccessDataSource>

使用了正确的控件名称(大小写完全相同),但是页面加载时返回在ControlParameter 'Surnames'中找不到控件'DropDownList1'。

你有什么建议吗?

编辑:如果有帮助,以下是堆栈跟踪

[InvalidOperationException: Could not find control 'DropDownList1' in ControlParameter 'Surname'.]
   System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +2107838
   System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +50
   System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +113
   System.Web.UI.WebControls.SqlDataSource.LoadCompleteEventHandler(Object sender, EventArgs e) +46
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Page.OnLoadComplete(EventArgs e) +9010786
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2350

AccessDataSource тњї DropDownList Тў»тљдтюеСИЇтљїуџётЉйтљЇт«╣тЎеСИГ№╝Ъ - Richard Deeming
它们位于同一页内的两个不同的ContentPlaceHolders中。 - InvalidSyntax
2
然后,ControlID 需要以包含 DropDownListContentPlaceHolderID 为前缀:http://stackoverflow.com/a/5719348/124386 - Richard Deeming
@RichardDeeming:你应该回复这个帖子,你的答案是正确的。 - InvalidSyntax
2个回答

8
ControlID需要在包含下拉列表的ContentPlaceHolder的ID前缀中:
<asp:ControlParameter 
   Name="Surnames" 
   ControlID="ContentPlaceholderID$DropDownList1" 
   PropertyName="SelectedValue" 
/>

请参见:https://stackoverflow.com/a/5719348/124386

我发现如果控件嵌套在多个元素中,您必须指定它们所有,因此最终我得到了类似这样的东西:YourContentPlaceHolder$YourASPxCallbackPanel$YourASPxPopupControl$YourASPxComboBox。 - Trajanus

0
此外,请确保您感兴趣的控件具有runat="server"属性。 唉。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接