C# 如何将DropDownList SelectedItem传递到EntityDataSource Select属性
我正在尝试将ddlCity DROPDOLLIST的选定值传递到EntityDataSource2 CommandText,其中“where p.city=@city”,但出现以下错误: 除非指定了AutoGenerateWhere==true或Where,否则无法指定Where参数C# 如何将DropDownList SelectedItem传递到EntityDataSource Select属性,c#,asp.net,entitydatasource,C#,Asp.net,Entitydatasource,我正在尝试将ddlCity DROPDOLLIST的选定值传递到EntityDataSource2 CommandText,其中“where p.city=@city”,但出现以下错误: 除非指定了AutoGenerateWhere==true或Where,否则无法指定Where参数 城市 找不到。。。 如果您有任何帮助,我们将不胜感激 <asp:EntityDataSource .... <WhereParameters> <asp:Cont
城市
找不到。。。
如果您有任何帮助,我们将不胜感激
<asp:EntityDataSource
....
<WhereParameters>
<asp:ControlParameter ControlID="costLimit" DbType="Int32"
DefaultValue="2500" Name="ordercost" PropertyName="SelectedValue"
ConvertEmptyStringToNull="true" />
</WhereParameters>
.....
</asp:EntityDataSource>
这是在EntityDataSource的Select属性中传递dropdownlist selectedvalue的正确版本
<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"
ConnectionString="name=medicaldb2Entities"
DefaultContainerName="medicaldb2Entities"
EntitySetName="Medicals"
Select= "it.[MedicalID], it.[medicalName], it.[city], it.[Region], it.[description], it.[Image], it.[adress]"
Where = "it.[city] = @city">
<WhereParameters>
<asp:ControlParameter ControlID="ddlCity" DbType="String"
DefaultValue="2500" Name="city" PropertyName="SelectedValue"
ConvertEmptyStringToNull="true" />
</WhereParameters>
</asp:EntityDataSource>
城市
找不到。。。
我已经试过了,我把它改为ControlID=“ddlCity”和Name=“City”。然后我再次将查询写为p.city=@city,但它不起作用。我假设您的代码中存在语法错误。您可以阅读Msdn中的语法或发布您的代码。我将一些属性添加到参数中。一旦您向我展示了正确的方法,我会将您的答案标记为正确,但我在下面发布的完整版本您可以查看本教程。我相信你会得到你的答案。谢谢,这看起来像是一个有用的教程,我必须阅读它
<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"
ConnectionString="name=medicaldb2Entities"
DefaultContainerName="medicaldb2Entities"
EntitySetName="Medicals"
Select= "it.[MedicalID], it.[medicalName], it.[city], it.[Region], it.[description], it.[Image], it.[adress]"
Where = "it.[city] = @city">
<WhereParameters>
<asp:ControlParameter ControlID="ddlCity" DbType="String"
DefaultValue="2500" Name="city" PropertyName="SelectedValue"
ConvertEmptyStringToNull="true" />
</WhereParameters>
</asp:EntityDataSource>