我Telerik Gridview
用于显示记录列表,我有超过10页我正在使用此gridview与以下常见事件代码复制粘贴(有一些小的更改)在所有这些页面上:
protected void Page_Load(object sender, EventArgs e) { DisplayRecords() } public void DisplayRecords() { //Grid view names are different on different pages. GridView1.DataSource=Fetching records from database. GridView1.DataBind(); } protected void GridView1_SortCommand(object sender, GridSortCommandEventArgs e) { DisplayRecords() } protected void GridView1_PageIndexChanged(object sender, GridPageChangedEventArgs e) { var index = e.NewPageIndex; DisplayRecords() } protected void GridView1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e) { var size = e.NewPageSize; DisplayRecords() }
这是我的一页继承自以下页面:
public partial class LoadSettings : ParentPage { //Load events and other events } [Serializable] public class ParentPage: RadAjaxPage { } Page 1:**ttt.aspx** public void DisplayRecords() { //Grid view names are different on different pages. GridView1.DataSource=this.GetAlltttData() GridView1.DataBind(); } public DataTable GetAlltttData() { using (var context = new MyDataContext()) { var data = from c in context.ttt select c; return MyDataContext.LINQToDataTable(data); } } Page 2:**bbb.aspx** public void DisplayRecords() { //Grid view names are different on different pages. GridView1.DataSource=this.GetAllbbbData() GridView1.DataBind(); } public DataTable GetAllbbbData() { using (var context = new MyDataContext()) { var data = from c in context.bbb select c; return MyDataContext.LINQToDataTable(data); } } protected void rgbbb_SortCommand(object sender, GridSortCommandEventArgs e) { DisplayRecords() } protected void rgbbb_PageIndexChanged(object sender, GridPageChangedEventArgs e) { var index = e.NewPageIndex; DisplayRecords() } protected void rgbbb_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e) { var size = e.NewPageSize; DisplayRecords() }
那么这可能是我可以将所有这些事件放在这个ParentPage页面中,只是从每个子页面调用而不是用这个事件污染我的每一页?
注意:在我的一些页面中,此DisplayRecords方法可以包含一些参数,但所有事件都是常见的.