<%@ Page %>
Alphabetical Paging in DataGrid
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.
is a software consultant, trainer, author, yoga mentor, and spiritual guide having 23+ years of experience in software development, consulting, and training. He conducts instructor-led online training courses
in ASP.NET Core, ASP.NET MVC, and Design Patterns 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 : Twitter Facebook