如何防止LinqDataSource Where子句在回发时重置? [英] How can I prevent the LinqDataSource Where clause from resetting on postback?

查看:86
本文介绍了如何防止LinqDataSource Where子句在回发时重置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一次单击按钮时以编程方式在绑定到GridView的LinqDataSource对象上设置where子句,但是当GridView重新绑定数据时(例如,当用户进行排序时),where子句会重置为空字符串.有什么方法可以防止这种情况发生,还是有更好的方法来过滤我的结果?

I'm trying to set the where clause on a LinqDataSource object bound to a GridView programmatically on a button click, but when the GridView rebinds data (for instance, when the user sorts) the Where clause resets back to the empty string. Is there a way to prevent this, or is there a better way to filter my results?

推荐答案

也许您只是将ViewState属性添加到页面/用户控件中,然后在所有回发中检索它?

Perhaps you just add a ViewState property into your page/user control and then retrieve it on all post back?


public string MyLinqSourceWhere 
{
    get { return (string)this.ViewState["MyLinqSourceWhere"]; }
    set { this.ViewState["MyLinqSourceWhere"] = value; }
}

public void Page_Load(object sender, EventArgs e) 
{
    this.myLinqSource.Where = this.MyLinqSourceWhere;
}

public void Button1_Click(object sender, EventArgs e) 
{
    this.MyLinqSourceWhere = " .... ";
    this.myLinqSource.Where = this.MyLinqSourceWhere;
}

如果这不起作用,那么也许绑定在LinqDataSource.Selecting事件上,将view状态的fetch属性添加到您的where子句中?一切都取决于

If that doesn't work, then perhaps bind on the LinqDataSource.Selecting event the fetch property from the viewstate to your where clause?? It all depends

这篇关于如何防止LinqDataSource Where子句在回发时重置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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