Pager style in data grid

G

GP

Hi,

I have a requirement for which I need to add a text "Page" before the
page numbers of the datagrid. It should look like " Page 1 Page 2 Page
3.......", all these being hyper links. I would like to add the label
"Page" to the datagrid header and footer.

Right now my pager style is set to show numbers only. Is there any
property to set the the text? I don't want to go for custom datagrid
for this requirement.

Please suggest.

Thanks Much,
Giri
 
J

Jeffrey Palermo [MCP]

Run this page and use it as your model. It works:

<%@ Page language="c#" Trace="True" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</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:DataGrid id="DataGrid1" runat="server"
ShowFooter="True" AllowCustomPaging="false" AllowPaging="True"
PageSize="3" PagerStyle-Mode="NumericPages">
</asp:DataGrid>
</form>
</body>
</HTML>

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace WebApplication1

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.DataGrid DataGrid1;


private void Page_Load(object sender, System.EventArgs e)

{

string[] stringArray = new string[10];

for(int i = 0; i < 10; i++)

{

stringArray = i.ToString();

}

DataGrid1.DataSource = stringArray;

DataGrid1.DataBind();

int upperBound = DataGrid1.Controls[0].Controls.Count - 1;

TableCell ctrl =
(TableCell)DataGrid1.Controls[0].Controls[upperBound].Controls[0];

Trace.Warn(ctrl.GetType().ToString());

foreach(Control ctl in ctrl.Controls)

{

Trace.Warn(ctl.GetType().ToString());

if(ctl is Label)

{

((Label)ctl).Text = "Page " + ((Label)ctl).Text;

}

if(ctl is LinkButton)

{

((LinkButton)ctl).Text = "Page " + ((LinkButton)ctl).Text;

}

}


}

#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.Load += new System.EventHandler(this.Page_Load);

}

#endregion


}

}

Best regards,
Jeffrey Palermo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top