我想ddlCity下拉列表中選擇的值傳遞到EntityDataSource2的CommandText其中「WHERE p.city = @city」但我得到以下錯誤:如何通過DropDownList中的SelectedItem到EntityDataSource選擇屬性
WhereParameters cannot be specified unless AutoGenerateWhere==true or Where is specified.
<tr id="SearchDropDown">
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=medicaldb2Entities"
DefaultContainerName="medicaldb2Entities" EnableFlattening="False"
EntitySetName="Medicals" Select="it.[medicalName], it.[city], it.[Region]">
</asp:EntityDataSource>
<td>
<td>
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlCity_SelectedIndexChanged"
DataSourceID="EntityDataSource1" DataTextField="city"
DataValueField="city">
</asp:DropDownList>
</td>
</tr>
</table>
<asp:ListView ID="ListView1" runat="server" DataSourceID="EntityDataSource2">
<LayoutTemplate>
<table>
<tr>
<td>
City
</td>
</tr>
<asp:PlaceHolder ID="ItemPlaceHolder" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("city") %>
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
Not Found...
</EmptyDataTemplate>
</asp:ListView>
<asp:EntityDataSource ID="EntityDataSource2" runat="server"
CommandText="SELECT p.MedicalID, p.medicalName, p.city, p.Region, p.description, p.Image, p.adress
FROM Medicals AS p WHERE p.city = @city"
AutoGenerateWhereClause="False"
ConnectionString="name=medicaldb2Entities"
DefaultContainerName="medicaldb2Entities">
<WhereParameters>
<asp:ControlParameter ControlID="ddlCity" DbType="String"
DefaultValue="2500" Name="city" PropertyName="SelectedValue"
ConvertEmptyStringToNull="true" />
</WhereParameters>
</asp:EntityDataSource>
任何幫助,將不勝感激
你可以看看這個教程[教程:實體數據源控件](http://blogs.msdn.com/b/adonet/archive/2008/06/18/tutorial-entity-data-source -control.aspx)。我相信你會得到你的答案。 – afzalulh
感謝它看起來像一個有用的教程,我必須讀它 – mctuna