如何在自定义的继承自GridView的控件中加入PagerTemplate行。
我想实现自定义分页,但不想每个页面都重复去写代码,因此决定扩展GridView空间,问题是如何动态创建PagerTemplate并加入到GridView中
主要是想实现不同的翻页方式。
我不想用现成的开发好的,未开源的控件。
------解决方案--------------------using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Saga.LivePortal.CustomControl
{
[ToolboxData( " <{0}:MyGridView runat=server> </{0}:MyGridView> ")]
public class MyGridView : System.Web.UI.WebControls.GridView, IPostBackEventHandler, IPostBackDataHandler
{
/// <summary>
///
/// </summary>
public MyGridView()
{
base.SelectedRowStyle.CssClass = "SelectedItem ";
base.RowStyle.CssClass = "GridItem ";
base.AlternatingRowStyle.CssClass = "GridAltItem ";
base.HeaderStyle.CssClass = "GridHeader ";
base.EditRowStyle.CssClass = "SelectedItem ";
base.RowStyle.Height = 20;
}
/// <summary>
///
/// </summary>
public delegate void OnReBindData();
/// <summary>
///
/// </summary>
public event OnReBindData ReBindData;
/// <summary>
/// const string stands for the navigate-to-first-page command sent from the grid
/// </summary>
private const string NAVIGATE_FIRST = "NAV_FIRST ";
/// <summary>
/// const string stands for the navigate-to-last-page command sent from the grid
/// </summary>
private const string NAVIGATE_LAST = "NAV_LAST ";
/// <summary>
/// const string stands for the navigate-to-previous-page command sent from the grid
/// </summary>
private const string NAVIGATE_PREVIOUS = "NAV_PREVIOUS ";
/// <summary>
/// const string stands for the navigate-to-next-page command sent from the grid
/// </summary>
private const string NAVIGATE_NEXT = "NAV_NEXT ";
private const string PAGESIZE_CONTROL = "PAGESIZE_CONTROL ";
private bool showPageNavigator = true;
public bool ShowPageNavigator
{
get
{
return showPageNavigator;
}
set
{
showPageNavigator = value;
}
}
#region Override GridView methods
public override void RenderControl(HtmlTextWriter writer)
{
try
{
writer.Write( " <table border=\ "0\ " class=\ "table_dark_inside\ " width=\ " " + this.Width.ToString() + "\ "
cellpadding=\ "0\ " cellspacing=\ "0\ "> ");
writer.Write( " <tr> <td align=\ "left\ " width=\ "100%\ "> ");
base.Render(writer);
writer.Write( " </td> </tr> ");
if (this.showPageNavigator)
{
writer.Write( " <tr> <td> ");
DrawPager(writer);