Here is the WebForm
-------------------------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb"
Inherits="DataGridPageProblem.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio.NET
7.0" name="GENERATOR">
<meta content="Visual Basic 7.0"
name="CODE_LANGUAGE">
<meta content="JavaScript"
name="vs_defaultClientScript">
<meta
content="
http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post"
runat="server">
<asp
ataGrid id="DataGrid1"
runat="server" PageSize="10" Height="0px" Width="100%"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="0">
<SelectedItemStyle Font-
Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle
ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-
Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<Columns>
<ASP:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="Last Name"></ASP:BoundColumn>
<ASP:BoundColumn
DataField="Title" SortExpression="Title"
HeaderText="Title" Visible="False"></ASP:BoundColumn>
<ASP:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="First Name"></ASP:BoundColumn>
</Columns>
<PagerStyle Font-
Bold="True" HorizontalAlign="Right" ForeColor="#330099"
BackColor="#FFFFCC" Mode="NumericPages"></PagerStyle>
</asp
ataGrid><BR>
</form>
</FORM></FORM>
</body>
</HTML>
---------------------------------------
Here is the code behind
----------------------------
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid
Private Const mstrAlphaPageCommand = "AlphaPage"
Private mstrAlphaPageList As String
= "A,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
Private mConnectionString As String = "Password=;User
ID=sa;Data Source=<<datasource>>;Initial Catalog=Northwind"
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web
Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub
Sub BindGrid(Optional ByVal alpha As String = "")
Dim cnn As New SqlConnection(mConnectionString)
Dim da As SqlDataAdapter
If alpha = "" Then
'da = New SqlDataAdapter("select
title,lastname,firstname from employees where lastname
like 'D%'", cnn)
da = New SqlDataAdapter("select
title,lastname,firstname from employees", cnn)
Else
da = New SqlDataAdapter("select
title,lastname,firstname from employees where lastname
like '" & LCase(alpha) & "%'", cnn)
End If
Dim ds As New DataSet()
da.Fill(ds, "employees")
DataGrid1.DataSource = ds
DataGrid1.CurrentPageIndex = 0
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_SelectedIndexChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs)
Handles DataGrid1.SelectedIndexChanged
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
Private Sub DataGrid1_ItemCommand(ByVal source As
System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles DataGrid1.ItemCommand
If e.CommandName = mstrAlphaPageCommand Then
DataGrid1.PageSize = System.Int32.MaxValue
DataGrid1.CurrentPageIndex = 0
Try
BindGrid(e.CommandArgument)
Catch excp As HttpException
DataGrid1.CurrentPageIndex = 0
BindGrid(e.CommandArgument)
End Try
End If
End Sub
Private Function GetPagingRow(ByVal objItem As
DataGridItem) As Table
Dim intColspan As Integer = objItem.Cells.Count
Dim tcNumPageRow As New TableRow()
tcNumPageRow.HorizontalAlign =
DataGrid1.PagerStyle.HorizontalAlign
Dim tcNumPageCell As TableCell
For Each tcNumPageCell In objItem.Cells
tcNumPageRow.Cells.Add(tcNumPageCell)
Next
Dim tcAlphaPageRow As New TableRow()
tcAlphaPageRow.HorizontalAlign =
DataGrid1.PagerStyle.HorizontalAlign
Dim tcAlphaPageCell As New TableCell()
tcAlphaPageCell.ColumnSpan = intColspan
Dim i As Integer
For i = 65 To 65 + 25
If mstrAlphaPageList.IndexOf(Chr(i)) <> -1 Then
Dim l As New LinkButton()
Dim lc As New LiteralControl()
lc.Text = " "
l.Text = Chr(i)
l.CommandName = mstrAlphaPageCommand
l.CommandArgument = Chr(i)
tcAlphaPageCell.Controls.Add(l)
tcAlphaPageCell.Controls.Add(lc)
Else
Dim lbl As New Label()
lbl.Text = Chr(i) & " "
tcAlphaPageCell.Controls.Add(lbl)
End If
Next
tcAlphaPageRow.Cells.Add(tcAlphaPageCell)
Dim tcTable As New Table()
tcTable.Width =
System.Web.UI.WebControls.Unit.Percentage(100)
tcTable.Rows.Add(tcNumPageRow)
tcTable.Rows.Add(tcAlphaPageRow)
Return tcTable
End Function
Private Sub DataGrid1_ItemCreated(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Pager Then
Dim tcPageTable As Table = GetPagingRow (e.Item)
Dim tcPageCell As New TableCell()
tcPageCell.ColumnSpan = DataGrid1.Columns.Count
tcPageCell.Controls.Add(tcPageTable)
e.Item.Cells.Clear()
e.Item.Cells.Add(tcPageCell)
End If
End Sub
End Class