gpt4 book ai didi

c# - 在 ControlParameter 'x' 中找不到控件 'y'

转载 作者:太空狗 更新时间:2023-10-29 22:52:47 26 4
gpt4 key购买 nike

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

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

ListView :

<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>

使用了正确的控件名称(大写字母也完全相同),但加载页面时返回Could not find control 'DropDownList1' in ControlParameter 'Surnames'。

对我在这里做错了什么有什么建议吗?

编辑:如果有帮助,这里是堆栈跟踪

[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

最佳答案

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

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

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

关于c# - 在 ControlParameter 'x' 中找不到控件 'y',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13610683/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com