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.

The requested operation requires elevation in Windows Vista

Posted by andy gaskell on Dec 13th, 2006

So I’ve been using Vista for a few weeks now and for whatever crazy reason I decided I needed to flush dns. I received this message: “The requested operation requires elevation”. Okay, to get around this go to All Programs, Accessories, right click Command Prompt and click Run as administrator. Good to go!

run as administrator

Update:
I’ve been running Vista for quite some time now and finally got fed up with User Account Control (UAC). What UAC really turns into is security by nagging so I disabled it altogether. To disable UAC open the Control Panel/User Accounts then click Turn User Account Control on or off. Uncheck the box. Click OK.

turn off uac in the control panel

turn off user access control

-