5

リストビューのドロップダウンリストを使用して結果をフィルタリングしようとしています。

データソースの選択クエリを次のように変更しました...

リストビュー:

<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 'Surnames' でコントロール '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
4

2 に答える 2

8

には、DropDownList を含む のIDControlIDをプレフィックスとして付ける必要があります。ContentPlaceHolder

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

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

于 2012-11-29T17:41:49.927 に答える