I'm trying to filter results using a dropdownlist for my listview.
I have altered the select query for the datasource as follows...
The 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>
The dropdownlist:
<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>
The correct Control name is used (the exact same caps as well), but the page on load returns Could not find control 'DropDownList1' in ControlParameter 'Surnames'.
Any suggestions on what I'm doing wrong here?
EDIT: Here is the stack trace if it helps
[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
The ControlID
needs to be prefixed with the ID of the ContentPlaceHolder
which contains the DropDownList:
<asp:ControlParameter
Name="Surnames"
ControlID="ContentPlaceholderID$DropDownList1"
PropertyName="SelectedValue"
/>
See also: https://stackoverflow.com/a/5719348/124386
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With