Asp.net 如何防止在回发时重置LinqDataSource Where子句?

Asp.net 如何防止在回发时重置LinqDataSource Where子句?,asp.net,where-clause,linqdatasource,Asp.net,Where Clause,Linqdatasource,我试图通过单击按钮以编程方式在绑定到GridView的LinqDataSource对象上设置where子句,但是当GridView重新绑定数据时(例如,当用户排序时),where子句将重置回空字符串。有没有办法防止这种情况发生,或者有没有更好的方法来过滤我的结果?也许您只需将ViewState属性添加到页面/用户控件中,然后在所有回发中检索它 public string MyLinqSourceWhere { get { return (string)this.ViewState["M

我试图通过单击按钮以编程方式在绑定到GridView的LinqDataSource对象上设置where子句,但是当GridView重新绑定数据时(例如,当用户排序时),where子句将重置回空字符串。有没有办法防止这种情况发生,或者有没有更好的方法来过滤我的结果?

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

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; } 公共字符串MyLinqSourceWhere { 获取{return(string)this.ViewState[“MyLinqSourceWhere”];} 设置{this.ViewState[“MyLinqSourceWhere”]=value;} } 公共无效页面加载(对象发送方,事件参数e) { this.myLinqSource.Where=this.MyLinqSourceWhere; } 公共无效按钮1\u单击(对象发送者,事件参数e) { this.MyLinqSourceWhere=“…”; this.myLinqSource.Where=this.MyLinqSourceWhere; } 如果这不起作用,那么可能会绑定到LinqDataSource。选择事件从viewstate获取属性到where子句??这要看情况而定