我有这段代码,我需要“where”子句中的“it.MembershipOption.Id”值为<%#Eval(“Id”)%>来自ListViewEventsOuter。我试图在“where”子句中添加Eval,但它会抛出错误。
这是怎么做到的?
<asp:ListView ID="ListViewEventsOuter" runat="server">
<ItemTemplate>
<a name='<%# Eval("Id") %>'></a>
<h3>Events for <%# Eval("Text")%> members</h3>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=Entities" Include="EventType, MembershipOption"
DefaultContainerName="Entities" EntitySetName="Events"
EntityTypeFilter="" Select="" Where='it.Active == True && it.MembershipOption.Id == [THIS VALUE TO COME FROM THE PREVIOUS ID IN LISTVIEW]'>
</asp:EntityDataSource>
<asp:ListView ID="ListViewEventsInner" runat="server">
ETC....
答案 0 :(得分:0)
解决方案:
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=Entities" Include="EventType, MembershipOption"
DefaultContainerName="Entities" EntitySetName="Events"
EntityTypeFilter="" Select="" Where='it.Active == True && it.MembershipOption.Id == @membershipOptionId'>
<WhereParameters>
<asp:Parameter Name="membershipOptionId" DbType="Int32" DefaultValue="2" />
</WhereParameters>
</asp:EntityDataSource>
protected void ListViewEventsOuter_ItemDataBound(object sender, ListViewItemEventArgs e)
{
ListViewDataItem item = (ListViewDataItem)e.Item;
MembershipOption m = (MembershipOption)item.DataItem;
string membershipOptionId = m.Id.ToString();
EntityDataSource entityDataSource1 = (EntityDataSource)e.Item.FindControl("EntityDataSource1");
Parameter parameter = entityDataSource1.WhereParameters[0];
parameter.DefaultValue = membershipOptionId.ToString();
}