2012-11-28 31 views
5

我正在尝试使用我的listview的下拉列表来筛选结果。在ControlParameter'y'中找不到控件'x'

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

ListView控件:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
     DataFile="~/App_Data/ASPNetDB.mdb" 
     SelectCommand="SELECT * FROM [tblNames] WHERE [email protected]"> 
     <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 
+0

“AccessDataSource”和“DropDownList”在不同的命名容器中吗? –

+0

它们位于同一页面内的两个不同的ContentPlaceHolders中。 – Imran

+2

然后'ControlID'需要以'ContentPlaceHolder'的'ID'作为前缀,其中包含'DropDownList':http://rockoverflow.com/a/5719348/124386 –

回答

8

ControlID需要与ContentPlaceHolder的其中包含的DropDownList的ID前缀:

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

参见: https://stackoverflow.com/a/5719348/124386

+0

我发现如果控件嵌套在多个元素中,你必须指定它们,所以我最后得到了类似于:YourContentPlaceHolder $ YourASPxCallbackPanel $ YourASPxPopupControl $ YourASPxComboBox – Trajanus

0

此外,请确保您的利益控制有ru NAT = “服务器”。哎呀。