我试图在单击按钮时以编程方式绑定(bind)到 GridView 的 LinqDataSource 对象上设置 where 子句,但是当 GridView 重新绑定(bind)数据时(例如,当用户排序时),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; }
如果这不起作用,那么也许可以在 LinqDataSource.Selecting 事件上绑定(bind)从 View 状态到您的 where 子句的 fetch 属性?这一切都取决于
关于asp.net - 如何防止 LinqDataSourceWhere 子句在回发时重置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2060004/