在加载时在linq数据源中添加where条件,并在下拉值更改时更改 [英] add where condition in linq datasource at load time and change when dropdown value change

查看:78
本文介绍了在加载时在linq数据源中添加where条件,并在下拉值更改时更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<h3 align="center">
               City :
               <asp:DropDownList ID="ddlCity" runat="server">
               </asp:DropDownList>
           </h3>
<asp:LinqDataSource

    ContextTypeName="ExampleDataContext"

    TableName="Products"

    Where="Price>@UserPrice"

    ID="LinqDataSource1"

    runat="server">

</asp:LinqDataSource>
<asp:GridView

    DataSourceID="LinqDataSource1"

    ID="GridView1"

    runat="server">
 <Columns>
<asp:BoundField DataField="city" HeaderText="City" SortExpression="city" ReadOnly="true" />
&lt;/Columns&gt;
</asp:GridView>


推荐答案

您是否尝试过这种方法
Did you tried like this
LinqDataSource1.Where = ddlCity.SelectedItem.value;
LinqDataSource1.WhereParameters.Add("name1", "value1");


1)将下拉列表的自动回传设置为true.
1)Set autopostback for dropdownlist to true.
<asp:DropDownList ID="ddlCity" runat="server" autopostback="True"> 
              </asp:DropDownList>


2)在下拉列表selectedindexchanged事件中设置where where 属性.
看看nit_singh的答案.


2)In dropdown list selectedindexchanged event set the where property of LinkDatasource1.
Look at nit_singh answer.


这篇关于在加载时在linq数据源中添加where条件,并在下拉值更改时更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆