【问题标题】:Could not find control 'x' in ControlParameter 'y'在 ControlParameter 'y' 中找不到控件 'x'
【发布时间】:2012-11-16 15:14:51
【问题描述】:

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

我已将数据源的选择查询更改如下...

列表视图:

<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

【问题讨论】:

  • AccessDataSourceDropDownList 是否在不同的命名容器中?
  • 它们位于同一页面内的两个不同的 ContentPlaceHolder 中。
  • 那么ControlID需要以ContentPlaceHolderID为前缀,其中包含DropDownListstackoverflow.com/a/5719348/124386
  • @RichardDeeming:你应该回答这个帖子,你的回答是正确的。

标签: c# asp.net visual-studio-2010 ms-access


【解决方案1】:

此外,请确保您的利益控制具有 runat="server"。啊。

【讨论】:

    【解决方案2】:

    ControlID 需要以包含 DropDownList 的ContentPlaceHolder 的 ID 为前缀:

    <asp:ControlParameter 
       Name="Surnames" 
       ControlID="ContentPlaceholderID$DropDownList1" 
       PropertyName="SelectedValue" 
    />
    

    另请参阅:https://stackoverflow.com/a/5719348/124386

    【讨论】:

    • 我发现如果控件嵌套在多个元素中,您必须全部指定它们,所以我最终得到了类似:YourContentPlaceHolder$YourASPxCallbackPanel$YourASPxPopupControl$YourASPxComboBox
    猜你喜欢
    • 1970-01-01
    • 2014-10-12
    • 2023-03-17
    • 2012-05-28
    • 2021-12-26
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多