By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

Pager style in data grid

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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] = 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

"GP" <gi**************@gmail.com> wrote in message
news:ea**************************@posting.google.c om...
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.