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
ataGrid id="DataGrid1" runat="server"
ShowFooter="True" AllowCustomPaging="false" AllowPaging="True"
PageSize="3" PagerStyle-Mode="NumericPages">
</asp
ataGrid>
</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