Click here to Skip to main content
13,408,530 members (42,551 online)
Click here to Skip to main content
Add your own
alternative version


110 bookmarked
Posted 4 Feb 2003

Letter/Alphanumeric Based Paging in ASP.NET

, 4 Feb 2003
Rate this:
Please Sign up or sign in to vote.
Explains one approach to adding letter-based paging to an ASP.NET datagrid control.
<!-- Download Links --> <!-- Article image -->

Sample Image - LetterBasedPaging.gif

<!-- Add the rest of your HTML here -->


This article explains one approach to adding letter-based paging to an ASP.NET DataGrid control. This solution adds a set of LinkButtons that correspond to the letters in the alphabet. When clicked, the DataGrid shows only records beginning with that letter. Navigation of large sets of data is greatly improved by using this method because fewer pages need be navigated to locate desired records.

For this example I have used the Northwind Database as the data source since it is commonly available and understood. Future articles will explain other methods used for navigating large amounts of data.


For this solution to work, we must have a DataGrid control or other data-bound control like a DataList. This will be used to render the data the user will be navigating. We must also have a Repeater control that will render a LinkButton control for each letter in the alphabet.

DataGrid Control

You can configure the DataGrid however you like. Below is a very simple example.

<asp:datagrid id="dgCustomers" runat="server" width="100%" />

In this example, it is not necessary to hook-up any events to the DataGrid. We will bind the data to the grid when we are ready by manually calling the dgCustomers.DataBind() method. Personally, I like having control of when the DataGrid gets bound, instead of letting it happen when the DataBinding event gets fired.

Repeater Control

This control requires a bit more work and set up. This control is what will show the letters as LinkButton controls. In the .aspx file, the following tags are added.

<asp:repeater id="rptLetters" runat="server">
    <asp:linkbutton id="lnkLetter" runat="server" 


            commandargument='<%# DataBinder.Eval(Container, "DataItem.Letter")%>'>
      <%# DataBinder.Eval(Container, "DataItem.Letter")%>

This renders LinkButton controls for every letter in the alphabet plus an "All" link that will show all records. When the letters are clicked, the web form posts back to the server and the ItemCommand event is fired with the letter clicked as the CommandArgument.

We use this argument to set the DefaultView.RowFilter property for the table to which we will be binding the main DataGrid In this case the main DataGrid is dgCustomers.

The code that sets the row filter is as follows, where dt is the main DataTable we will be navigating, and _letterFilter is the letter that was clicked.

dt.DefaultView.RowFilter = "CompanyName LIKE '" + _letterFilter + "%'";

It is important to note details about the DataSource that this control is actually bound to. That will now be discussed.

Letters Data Source

Below describes in detail the process of creating a custom table that the previously discussed rtpLetter control is bound to.

First we create an array of what we want to add to our table:

string[] letters = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
                     "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
                     "W", "X", "Y", "Z", "All"};

Next we define the schema of the table that will contain the letters.

// Create the scheme of the table
dt.Columns.Add(new DataColumn("Letter",

Now that we have a table, lets add all the items in the previously created letters array.

// Populate the data table with the letter data
for (int i = 0; i < letters.Length; i++) {
  DataRow dr = dt.NewRow();
  dr[0] = letters[i];

Now all you have to do is set rptLetters.DataSource to the newly created table.

// Bind the data's default view to the grid
rptLetters.DataSource = dt.DefaultView;

In the sample code provided in the zip file there are many other little techniques for optimizing the performance of the web form, like caching certain information in the Session and ViewState. For brevity I have excluded those details from this article.


The purpose of this article was to provide you with the information needed to implement letter-based paging in ASP.NET data-bound controls. I have tried to keep it short and to the point. If there are important things that I missed, please let me know and I will update this article.

Revision History

4 February 2003: Original Article


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Joseph S. Keller
Web Developer
United States United States
Joseph S. Keller works at Advanced Business Technology as a lead developer for the most widely used Sports Assigning Software. Besides this hands experience he enjoys research in music composition. Joseph also improves his skills by writing technical articles and gaining certifications offered by Microsoft.

You may also be interested in...

Comments and Discussions

GeneralVB Version Pin
Jason Tepe3-Sep-04 5:48
memberJason Tepe3-Sep-04 5:48 
GeneralRe: VB Version Pin
cvilla22-Sep-04 12:36
membercvilla22-Sep-04 12:36 
GeneralRe: Another VB Version Pin
HoochDEA15-Feb-06 16:56
memberHoochDEA15-Feb-06 16:56 
GeneralRe: Another VB Version Pin
yukijocelyn23-Aug-07 23:45
memberyukijocelyn23-Aug-07 23:45 
GeneralRe: Another VB Version Pin
Matt Penman18-Jul-08 4:43
memberMatt Penman18-Jul-08 4:43 
GeneralRe: Another VB Version Pin
Brock Dandy29-Oct-08 6:56
memberBrock Dandy29-Oct-08 6:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180212.1 | Last Updated 5 Feb 2003
Article Copyright 2003 by Joseph S. Keller
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid