Hi Daniel,
Welcome to ASP.NET newsgroup. As for the modifying the ASP.NET DataGrid's
buildin pager style's question. I think we may start from the following
means:
The ASP.NET's Buildin pager is rendered in the Pager Section of the
datagrid, we can access that section through the ItemCreated event. The
Pager section is infact an TableCell , and all the number, [...] links are
all Linkbuttons in that TableCell. So if you want to do any modification or
customization, we should manually access that TableCell and modify it's
Controls colleciton. Here is a test page I've built, you can have a look:
=========aspx=============
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>custompager</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp

ataGrid id="dgPager" runat="server" AllowPaging="True"
PageSize="5" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Email"
HeaderText="Email"></asp:BoundColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp

ataGrid>
</form>
</body>
</HTML>
=======code behind=======
public class custompager : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgPager;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
dgPager.DataSource = GetDataSource();
dgPager.DataBind();
}
}
private DataTable GetDataSource()
{
DataTable dt = new DataTable("Users");
dt.Columns.Add("ID", typeof(long));
dt.Columns.Add("Name");
dt.Columns.Add("Email");
for(int i=0;i<500;i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = "Name_" + i;
dr[2] = "Email_" + i;
dt.Rows.Add(dr);
}
return dt;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgPager.ItemCreated += new
System.Web.UI.WebControls.DataGridItemEventHandler(this.dgPager_ItemCreated)
;
this.dgPager.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgPager_PageI
ndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void dgPager_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgPager.CurrentPageIndex = e.NewPageIndex;
dgPager.DataSource = GetDataSource();
dgPager.DataBind();
}
private void dgPager_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Pager)
{
LinkButton btnFirst = new LinkButton();
LinkButton btnLast = new LinkButton();
btnFirst.ID = "btnFirstPage";
btnFirst.Text = "First Page";
btnLast.ID = "btnLastPage";
btnLast.Text = "Last Page";
TableCell tc = e.Item.Controls[0] as TableCell;
if(tc != null)
{
tc.Controls.AddAt(0,btnFirst);
tc.Controls.AddAt(tc.Controls.Count, btnLast);
}
Response.Write("<br>" + e.Item.Controls[0].Controls.Count);
}
}
}
=================================
There are also many tech articles over other internet development community
discussing on the similiar problem. HTH.
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)