我使用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方法中的任何内容?
发布于 2018-06-26 05:26:24
我放弃了在调谐器中设置LinqDataSource,而是使用编程数据源来更好地控制where子句。
密码如下-
d = (from u in db.prop2Shows select u).Where(a => a.active==true &&
a.list==true);
Repeater1.DataSource = d;
Repeater1.DataBind();https://stackoverflow.com/questions/51009779
复制相似问题