![](/img/trans.png)
[英]Add WhereParameters to LinqDataSource in Selecting event
[英]LinqDataSource selecting issue
我將LinqDataSource與Repeater控件一起使用,以檢索和顯示取決於DropDownList SelectedValue的數據。
我的代碼如下-
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);
}
}
加載表單時,我按預期獲得所有記錄,但是當我更改DropDownList1 SelectedValue(選擇特定城市)並單擊Button1時,我得到相同的結果,即所有記錄
我需要在LinqDataSource1_Selecting方法中進行任何更改嗎?
我放棄了在tuntime中設置LinqDataSource的方法,而是在我可以更好地控制Where子句的地方使用程序化數據源。
代碼如下-
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.