Using the digg API in an ASP.NET Page

Posted by andy gaskell on Apr 20th, 2007

Digg released their API yesterday - I haven’t really done much with RESTful web services because in the .net world, most of the time SOAP/WSDL is used. I thought a very basic RESTful web service project would be useful for other .net developers.

This example gets a list of all topics that digg offers. The code is pretty simple:

// Create the web request, change the appkey to for your applications
HttpWebRequest request = WebRequest.Create("http://services.digg.com/topics?appkey=http%3A%2F%2Fgaskell.org") as HttpWebRequest;

// won't get a response from digg if UserAgent is not set
request.UserAgent = ".net"; 

// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
     // Get the response stream
     StreamReader reader = new StreamReader(response.GetResponseStream());

     DataSet ds = new DataSet();
     ds.ReadXml(reader);

     this.topicsGridView.DataSource = ds.Tables[1];
     this.topicsGridView.DataBind();
}    

Download the project or check out the live demo

Now with 100% more .net

Posted by andy gaskell on Apr 18th, 2007

I host my blog on the fantastic WordPress blog platform which typically runs on the LAMP stack. That means I can’t put up live demos of my .net posts so I created a new .net playground at http://dotnet.gaskell.org. I’ll have live examples of all of my projects as well as project downloads.

To get things started here’s a live demo of the digg style paging in asp.net project I created.

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.

Next »