读这个?
The Entity Framework and ASP.NET - Filtering, Ordering, and Grouping Data
更新:Northwind 产品和类别表的示例。
DropDownList 列出类别,GridView 显示按类别筛选的产品。
ASPX
<asp:DropDownList ID="uxTreeView1" runat="server"
AutoPostBack="true"
AppendDataBoundItems="true"
DataSourceID="EntityDataSource1"
DataTextField="CategoryName"
DataValueField="CategoryID"
OnSelectedIndexChanged="uxTreeView1_SelectedIndexChanged">
<asp:ListItem Text="Select Category" Value="0"></asp:ListItem>
</asp:DropDownList>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=NorthwindEntities"
DefaultContainerName="NorthwindEntities" EnableFlattening="False"
EntitySetName="Categories" Select="it.[CategoryID], it.[CategoryName]">
</asp:EntityDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataSourceID="EntityDataSource2"
DataKeyNames="ProductID">
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="ProductName"
ReadOnly="True" SortExpression="ProductName" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID"
ReadOnly="True" SortExpression="CategoryID" />
</Columns>
</asp:GridView>
<asp:EntityDataSource ID="EntityDataSource2" runat="server"
ConnectionString="name=NorthwindEntities"
DefaultContainerName="NorthwindEntities" EnableFlattening="False"
EntitySetName="Products"
Select="it.[ProductID], it.[ProductName], it.[CategoryID]">
</asp:EntityDataSource>
ASPX.CS
protected void uxTreeView1_SelectedIndexChanged(object sender, EventArgs e)
{
EntityDataSource2.WhereParameters.Clear();
EntityDataSource2.AutoGenerateWhereClause = true;
//alternatively
//EntityDataSource2.Where = "it.[CategoryID] = @CategoryID";
EntityDataSource2.WhereParameters.Add("CategoryID", TypeCode.Int32, uxTreeView1.SelectedValue);
}
这是你想要的?