Digg style custom paging for GridViews in ASP.NET

Posted by andy gaskell on Apr 12th, 2007

I’ve been on a bit of a digg kick lately and I like how they handle paging so I decided to create a GridView control that uses custom paging similar to digg’s. The algorithm is based on this post. As far as html output goes, this should be fairly close to the actual output on digg and I’m using digg’s stylesheet in the demo.

About the algorithm (from Stranger Studios):

  1. The pagination object has a “previous” and “next” button which takes the user to the next page. The previous button is disabled on the first page. Similarly, the next button is disabled on the last page.
  2. The pagination object will always display links to the first two pages and the last two pages of the set.
  3. The pagination object will always display links to the first x (adjacents in the code) pages before and after the current page.
  4. The pagination object will only show at most 5+2x links (first two + prior x + current page + next x + last two). All links not shown will be replaced by …

A little preview:
digg style paging preview

You can download the project here. I didn’t spend a ton of time testing this code, please leave any bug reports in the comments – Thanks!

Update: Changed the code a bit – paging is now handled via query string instead of posting back. Not a huge deal but the code is easier to read.

Digg It button User Control for ASP.NET

Posted by andy gaskell on Apr 7th, 2007

I came across Tuggo’s excellent diggIT plugin for WordPress and thought it’d be cool to make an ASP.NET User Control that provides similar functionality. The control is really easy to use.

Here’s the basic tag:

<uc1:DiggItButton  ID="DiggItButton"
                   runat="server"
                   Url="http://gaskell.org"
                   Title="Test title"
                   Body="Test body" />

You don’t need to set the Url, Title and Body properties in the tag, they are also available as public properties in the codebehind. The only property that is required to be set is the Url property – if you pass in the Title and/or Body, digg will pre-populate those fields. Digg also asks that you url encode your strings and this control handles that for you. Check out the code and sample page here.

You can view an example of the control here at gifninja. Enjoy!

Setting a default button using Master Pages in ASP.NET

Posted by andy gaskell on May 2nd, 2006

This one’s pretty easy, but wasn’t apparent to me at first. Put this code in your Page_Load to set a default button in master pages:

this.Form.DefaultButton = this.YOUR_DEFAULT_BUTTON.UniqueID;

-