本文介绍了如何通过DropDownList中的SelectedItem到EntityDataSource选择属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想ddlCity DropDownList的选定值传递到EntityDataSource2的CommandText其中WHERE p.city = @city但我得到以下错误:
<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>
Any help would be appreciated
解决方案
You can use
<asp:EntityDataSource
....
<WhereParameters>
<asp:ControlParameter ControlID="costLimit" DbType="Int32"
DefaultValue="2500" Name="ordercost" PropertyName="SelectedValue"
ConvertEmptyStringToNull="true" />
</WhereParameters>
.....
</asp:EntityDataSource>
这篇关于如何通过DropDownList中的SelectedItem到EntityDataSource选择属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!