有两个linqdatasource,一个绑定到下拉列表,另一个绑定到gridview。 DropDownList是控制参数。 我的代码:
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="TestPortalDataContext" EntityTypeName="" EnableUpdate="true" EnableDelete="True"
EnableInsert="True" TableName="AllSuitesWithFeatureNames"
Where="FeatureName==@FeatureName" OrderBy="SuiteID desc" OnSelecting="LinqDataSource1_Selecting">
<WhereParameters>
<asp:QueryStringParameter DefaultValue="" Name="SuiteID" QueryStringField="SuiteID" />
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="1"
Name="FeatureName" PropertyName="SelectedValue" Type="string" />
</WhereParameters>
</asp:LinqDataSource>
<asp:LinqDataSource ID="LinqDataSource2" runat="server"
ContextTypeName="TestPortalDataContext" EntityTypeName=""
TableName="AllFeatures" OrderBy="FeatureName">
</asp:LinqDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="DDDropDown"
DataSourceID="LinqDataSource2" DataTextField="FeatureName" DataValueField="FeatureName" AutoPostBack="True" >
</asp:DropDownList>
由于LinqDataSource1中有一个控制参数,因此每次我必须在下拉列表中选择正确的FeatureName进行搜索。我知道在sql中很容易在所有表格中搜索。但是我怎样才能搜索所有LinqDataSource1 linq方式?
答案 0 :(得分:0)
试试这个。假设
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="DDDropDown"
DataSourceID="LinqDataSource2" DataTextField="FeatureName" DataValueField="FeatureName" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
LinqDataSource1.Where = "FeatureName==" + DropDownList1.SelectedValue;
LinqDataSource1.DataBind();
gridView.DataSource = LinqDataSource1;
gridView.DataBind();
}