我在一个网格视图上有一个自定义分页器模板,客户现在希望将其应用于同一站点内的多个其他网格视图。 似乎扩展 GridView 对象最有意义,但我不清楚如何动态创建分页器模板。
关于如何实现这一目标有什么建议吗?
这个有用吗:
gridview.PagerTemplate = Page.LoadTemplate("CustomPager.ascx");
http://msdn.microsoft.com/en-us/library/6d5z5yty(VS.80).aspx
更新
延伸:
public class CustomGridView : GridView {
public override void OnInit(EventArgs e) {
base.OnInit(e);
this.PagerTemplate = Page.LoadTemplate("CustomPager.ascx");
}
}
我不知道为什么这篇文章直到现在才出现,但我在 DotNetSlackers 上找到了一个很好的教程,它让我朝着正确的方向前进。
http://dotnetslackers.com/articles/gridview/Custom-GridView-with-Paging-and-Filtering.aspx
不幸的是,我确实必须动态创建分页器控件。 如果有人知道更好的方法,我仍然会洗耳恭听,因为我更愿意像 PagerTemplate 中那样编写 HTML。