简体   繁体   中英

LinqDataSource selecting issue

I use LinqDataSource with a Repeater control to retrieve and show data depends on 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

Do I need to change anything in my LinqDataSource1_Selecting method ?

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.

Code follows -

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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