我正在尝试使用列表下拉列表来过滤结果。
我修改了数据源的select查询如下.
列表视图:
<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‘姓氏’中找到控件'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发布于 2012-11-29 17:41:49
ControlID需要以包含DropDownList的ContentPlaceHolder的ID作为前缀:
<asp:ControlParameter
Name="Surnames"
ControlID="ContentPlaceholderID$DropDownList1"
PropertyName="SelectedValue"
/>发布于 2017-07-10 19:07:25
此外,确保您的兴趣控制有runat=“服务器”。啊。
https://stackoverflow.com/questions/13610683
复制相似问题