Online courses in ASP.NET MVC, ASP.NET Core, and Design Patterns conducted by Bipin Joshi. Read more...
Learn ASP.NET MVC, ASP.NET Core, and Design Patterns through our online training programs. Courses conducted by Bipin Joshi on weekends. Read more details here.

<%@ 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 a software consultant, trainer, author and a yogi having 21+ years of experience in software development. He conducts online courses in ASP.NET MVC / Core, jQuery, AngularJS, and Design Patterns. He is a published author and has authored or co-authored books for Apress and Wrox press. Having embraced Yoga way of life he also teaches Ajapa Meditation to interested individuals. To know more about him click here.

Get connected : Twitter  Facebook  Google+  LinkedIn

Posted On : 17 Aug 2002



Tags : ASP.NET Web Forms Server Controls Data Controls