Hands-On ASP.NET Core 3.1 : Learn MVC, Razor Pages, Web API, Entity Framework Core, and Blazor. Private online coaching for software developers. Click here to know more.

<%@ Page %>

Alphabetical Paging in DataGrid

Introduction

All of you must be familiar with paging features of ASP.NET DataGrid. The built-in paging is based on number of records per page. In certain application displaying just the certain number of rows per page is not sufficient. Consider for example that you are building a contact manager or address book. Typically such data is accessed alphabetically. All the records are required to be indexed as per alphabets i.e. all records starting with A should be displayed as a single page and so on. This article tells you how to do such alphabetical paging in DataGrid.

Setting DataGrid Footer

In order to page the DataGrid based on alphabets, we need to display alphabets instead of normal page numbers. This can be done by adding link buttons in the DataGrid footer. You may add the link buttons at design time or at run time. The later approach is more flexible and gives more control on which alphabets you want to display. You can add link buttons at run time by using DataGrid1_ItemCreated event. You also need to use CommandName and CommandArgument properties of the link button to identify them uniquely.

Handling the Paging

When user clicks on any of the alphabet, the form is posted back and DataGrid1_ItemCommand event will be raised. Inside the event you can take action based on the CommandName and CommandArgument of the link button that caused the event to be raised. Typically this action will be to fetch records for the specified alphabet and bind the DataGrid again.

Source Code and Screen Shot

Full source code of the article is available in the download accompanying the article as VS.NET project. Following figure shows sample run of the application.


Bipin Joshi is an independent software consultant, trainer, author, yoga mentor, and meditation teacher. He has been programming, meditating, and teaching for 24+ years. He conducts instructor-led online training courses in ASP.NET family of technologies for individuals and small groups. He is a published author and has authored or co-authored books for Apress and Wrox press. Having embraced the Yoga way of life he also teaches Ajapa Yoga to interested individuals. To know more about him click here.

Get connected : Facebook  Twitter  LinkedIn  YouTube

Posted On : 17 August 2002


Tags : ASP.NET Web Forms Server Controls Data Controls


Subscribe to our newsletter

Get monthly email updates about new articles, tutorials, code samples, and how-tos getting added to our knowledge base.

  

Receive Weekly Updates