通过从父级检索条件将网格数据保留在用户控件中
我有一个用户控件,我想在其中包含网格,这样我就不必在每个页面上复制该网格。除非我排序、分页或执行任何回发操作,否则用户控件会重新加载并丢失其数据源。我的计划是从父页面检索搜索条件(因为它已经从条件控件中获取了)。这样,当调用 NeedDataSource 时,它仍然具有传回正确结果的标准。
我如何到达您看到 SuperSearch 的位置,无论哪个页面可能是像 StateToState 这样的父页面。
public SearchCriteria SearchCriteria
{
get
{
Page parent = this.Page;
if (parent != null)
{
var superSearch = parent as SuperSearch;
if (superSearch != null) return superSearch.SearchCriteria;
}
return new SearchCriteria();
}
}
I have a usercontrol that I want to have the grid inside so I don't have to duplicate that grid on every page. Except when I sort, page, or anything that does a post back the usercontrol reloads and loses its datasource. My plan is to retrieve the search criteria from the parent page(since it already has it from the criteria controls). That way when the NeedDataSource is called it still has the criteria to pass back the right results.
How do I get where you see SuperSearch to be whichever page might be the parent like StateToState.
public SearchCriteria SearchCriteria
{
get
{
Page parent = this.Page;
if (parent != null)
{
var superSearch = parent as SuperSearch;
if (superSearch != null) return superSearch.SearchCriteria;
}
return new SearchCriteria();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的用户控件上创建一个事件处理程序“event EventHandler NeedSearchCriteria”,该事件处理程序在您的父页面上触发 在
您的 aspx 页面上:
在后面的代码中: 在
后面的用户控件代码中:
Create an event handler 'event EventHandler NeedSearchCriteria' on your usercontrol that gets fired on your parent page
On your aspx page:
In the code behind:
And on the usercontrol code behind: