简体   繁体   English

LinqDataSource选择问题

[英]LinqDataSource selecting issue

I use LinqDataSource with a Repeater control to retrieve and show data depends on DropDownList SelectedValue. 我将LinqDataSource与Repeater控件一起使用,以检索和显示取决于DropDownList SelectedValue的数据。

my Code follows - 我的代码如下-

protected void Button1_Click(object sender, EventArgs e)
{
    Repeater1.DataBind();
}


protected void DropDownList1_DataBound(object sender, EventArgs e)
{
    DropDownList1.Items.Insert(0, "--");
}

protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
    if (DropDownList1.SelectedValue != "--")
    {
        e.WhereParameters.Add("city", DropDownList1.SelectedValue);
    }

}

When form is loaded I get all the records as expected but when I change DropDownList1 SelectedValue (select a specific city) and than click Button1 I get the same results, that is all the records 加载表单时,我按预期获得所有记录,但是当我更改DropDownList1 SelectedValue(选择特定城市)并单击Button1时,我得到相同的结果,即所有记录

Do I need to change anything in my LinqDataSource1_Selecting method ? 我需要在LinqDataSource1_Selecting方法中进行任何更改吗?

I gave up on setting the LinqDataSource in tuntime, instead I use a programmatic data source where I have better control over the Where clause. 我放弃了在tuntime中设置LinqDataSource的方法,而是在我可以更好地控制Where子句的地方使用程序化数据源。

Code follows - 代码如下-

d = (from u in db.prop2Shows select u).Where(a => a.active==true && 
a.list==true);
    Repeater1.DataSource = d;
    Repeater1.DataBind();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM