May 30, 2007

Quick Tip: Order By 1 Desc

Did you know that instead of specifying the name or column alias in a SQL Server Order By expression you can optionally use an integer representing the position of the column name or alias within the select list you want to sort by.   So both of these queries return the same result set ...-- find me the last 10 log entries select top 10 * from adventureworks.dbo.databaselog order by databaselogid desc -- find me the last 10 log entries select top 10 * from adventureworks.dbo.databaselog order by 1 desc .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; }...

May 21, 2007

Ajax.Net Example: Using an UpdatePanelAnimationExtender to place an animated gif over a GridView

 I recently was working on an Asp.Net project that contained quite a few search pages.  These pages all followed a similar structured pattern where the user had a set of fields they could filter on by typing in values and pressing the search button.  The results were displayed in a GridView where the user could sort by clicking on column headers, export the results to excel, etc...  To help improve user experience, we placed each of the GridViews in an asp UpdatePanel so while the user refined the search (sorting, adding or removing additional filters), only the GridView would be refreshed and not the entire page.  Additionally, we wanted to add a few standard UI cues (disabling the Search button, fading out the GridView, and placing a progress indicator over the GridView) letting the user know an operation was currently in progress. Download Code | View live demo It turned out that adding these UI cues was pretty easy...

May 20, 2007

Part II: Simple example of shading zip-code boundaries using Virtual Earth

In the original article, I showed an example of plotting zip-code boundaries using Microsoft Virtual Earth and Ajax.Net.  I received some feedback from John (SoulSolutions) suggesting that the transmission of latitude and longitude points could be optimized by using googles compression algorithm (described here) which exploits that fact that lat/lons can benefit from compression when there is little difference between adjacent lat/longs within a given sequence.  I thought this was an interesting suggestion so I updated the example to include this compression algorithm.  Here is the rundown of the changes that I made: The ZipCodeService now returns an encoded string of lat/lons instead of the original format that had the individual lat/lons comma separated and the pair pipe separated The ZipCode.js file now contains a routine that decodes the result from the ZipCodeService and builds a VELatLong array from the decoded points I pulled over the javascript/C# source provided by John for encoding/decoding the points.  Download Code I used fiddler to check-out the difference in...

May 15, 2007

Code Review Tool that integrates with Visual Source Safe

It has been over three years since I worked on a team that had any notion of a structured code review.  I previously worked for Microsoft and the team I was part of had a sophisticated process in place to ensure the stability of the code base.  This process included a 10 step checklist that a developer had to walk through before they were allowed to check changes into the repository.  It didn't matter if you changed only a single line of code, only added a few unit tests or completely rewrote the whole application, you still had to follow the same process before you changes could be committed.  One of the items on the checklist was for getting your code peer reviewed.  And it usually went something like this 1.  The developer sends out an email to 3 other developers and quality assurance members referencing the number of the bug/feature they were working on (no changes...

Topics: General .Net

May 14, 2007

Single config file - multiple deployment environments (i.e. dev, qa, prod)

A common problem most application developers face at one time or another is managing the deployment of the environment specific configuration elements their application depends on.  Most often these elements include items like connection strings, file paths or other settings the application requires access to during runtime.  I recently tackled this problem and came up with a solution that seems to work pretty well (we have been using it for the past 4 months without any issues) and fits in great with our automated build enviornment.  Download code (http://mattberseth.com/downloads/managing_environment_config_settings.zip) for this article. My approach was pretty simple.  I wanted the build process to substitute all of the environment specific config settings while it was making the build.  So if I was doing a regular build at my desk, Visual Studio would automatically use the 'dev' environment settings, but when the automated build server did a 'qa' or 'prod' build, the correct settings would be applied here as well.  1.  First I identified...

Topics: Build

May 12, 2007

Plotting Zip-Code Boundaries using ASP.Net AJAX and Microsoft Virtual Earth

During a recent project, I had the opportunity to play around with the Virtual Earth Map Control from Microsoft (http://dev.live.com/virtualearth/sdk/).  The goal of the project was to display zip codes by outlining its boundary.  In the end we decided to go a different route, but I thought I would share the prototype (~200 lines of code including markup).  The sample app is an asp.net web page with a drop down list that allows the user to select the zip-code they want shaded.  When the search button is clicked, I make a webservice call to the ZipCodeSearch webservice (using ASP.Net AJAX), find the points that make up the latitude/longitudes for the provided zip-code, then hand these coordinates off the the Virtual Earth map control so it can plot them for me.  Download code | View live demo [Update 10/11/2007]:  If you are looking for the zip code data set I used for this post, you can read how to get it here. ...

Topics: ASP.NET

May 07, 2007

Displaying summary data in an ASP.NET GridView

A recent project I worked on had the requirement of displaying a summary row for a GridView.  Most of the approaches I came across had code that handled the GridView's RowDataBound event handler and then did the summary book keeping if the row being bound was a DataRow, and injected the summary value (total/max/min) if the row was a Footer.  Similiar to the followingprotected void ProductsInCategory_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ... Increment the running totals ... } else if (e.Row.RowType == DataControlRowType.Footer) { ... Display the summary data in the footer ... } } This appraoch works, but I thought it would be nice if this book-keeping logic could be factored out into its own component and specified via markup.  I started playing around with implementing a prototype to see how it would work.  Here was my basic approach: Create a GridView extension componenet that hooks into the RowDataBound...

Topics: ASP.NET

May 01, 2007

7 simple steps to ajax-enable your ASP GridView

I recently used the AJAX.NET framework in a project and I was impressed with how easy it was to implement and how much it improved the usability of our pages.  Our project had quite a few advanced search pages where users can enter in a number of different filters and then hit the search button (usually iteratively - filter/search; filter/search; etc...).  Before the Ajax framework and Ajax Control Toolkit were applied to the pages, each time the user would tweak a filter or request a different column sort, the complete page would refresh.  After adding Ajax to the pages, just the GridView is re-rendered giving the user the much nicer web 2.0 user experience.  Anyway, here are the steps I followed for adding these features to our project ... Download code | View live demo Step 1: Download and install the official ASP.NET Ajax Framework Microsoft released the RTM version of the Ajax framework (previously named Atlas) for .Net 2.0...


Consulting Services

Yep - I also offer consulting services. And heck, I'll do just about anything. If you enjoy my blog just drop me an email describing the work you need done.

Recent Comments

  • TimothyP wrote: I work with tons of developers who haven't even got a clue what Twitter of Facebook is. In fact, it'...
  • Janko wrote: Yes it's strange that people think it's ok to blog at work but consider unethical to use facebook. P...
  • Kam Lagan wrote: Hi Matt, The numbers do seem a little "off" to what you perceived the community would be like. But...
  • Siderite wrote: You're kidding me! So the people that don't blog think it is ok to blog at work (maybe because they ...
  • Guy Harwood wrote: Good to see the results. one typo.... 'What best describes your current job title?' appears twice,...
  • sirrocco wrote: One problem with : DEV I DEV II DEV III was that I didn't know what it meant :( .(is it common ...
  • Jack wrote: How many person fill the survery? Blog is very common, so I don't think 71.5% is high. Maybe our bos...
  • Andy wrote: Done. The developer1, developer2 question - not sure how meaningful the results are going to be for ...