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 <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ca99bfb8a4aba7afb9f78a99bfb8a4aba7afb9">[email protected]</a>">
<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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
Method 2
Additionally, make sure your control of interest has runat=”server”. Argh.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0