ASP.NET 2.0 DataGrid Custom Paging[by Ted Heng]

ASP.NET 2.0 DataGrid Custom Paging

Author: Ted Heng, Senior Consultant, Premier Partner ISV, US Enterprise Services, Microsoft Corporation

June 30, 2010

 

Contents

Introduction. 1

Technique. 1

Screenshots. 2

Source Code. 2

Conclusion. 6

 

 

Introduction

In this blog, I will demonstrate a technique where you can customize your paging behavior in combination with the standard DataGrid control’s NumericPage paging feature.  The standard paging modes for the DataGrid are NumericPages and PrevNext.  You can enable AllowCustomPaging to do a more complex paging customization, but that requires you to manipulate the VirtualItemCount and others which isn’t always necessary for many paging customization needs.  So, this is the simplest way that I know how to accomplish custom paging.

 

Technique

The DataGrid creates two paging rows one at the top of the table if the option is to display the paging navigation there and/or another one at the bottom of the table if the option is to display there.  If you don’t use the auto-generated columns, the paging table cell spans across the entire table and there is a Controls list that has the numeric page links.  This technique for adding custom paging behaviors to the DataGrid control requires manipulating this Controls list.  Here are the main steps that you need to do.

1.      Add the Init event handler for the DataGrid control – in this Init event handler, create the additional navigation controls, such as, ImageButton or LinkButton, to be added to the paging Controls list.  If you would like to have the paging behavior to include First Page, Previous Page, Numeric Pages, Next Page, and Last Page, you will need to add First Page, Previous Page, Next Page, and Last Page link controls to the Controls list.

2.      For each additional navigation link, create an event handler for the Click event.  This allows your program to handle the event when the user clicks on the link.

3.      Add the ItemCreated event handler for the DataGrid control – you will add the additional navigation links to the Controls list in this event handler.

Screenshots

Using the AdventureWorksLT2008, here is the list from the Customer table.

Source Code

Here is the entire source code for the default.aspx.

Here is the entire source code for default.aspx.cs.

Conclusion

This technique shows you how to customize your navigation behaviors with very simple steps and still leveraging the built-in paging feature of the DataGrid control.  I hope that this is useful for your application.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值