Monthly Archives: October 2008

Use jQuery and quickSearch to interactively search any data

While reviewing my latest post’s outbound click-through stats, I noticed that most of you found Rik LomasquickSearch more interesting than the rest. In light of that interest, I’ve decided to show you an example of how you might implement its functionality in conjunction with ASP.NET.

For this demonstration, I’m going to use Delicious as a source of sample data to apply the technique to. I’m sure you’re getting tired of my RSS feed as demo data, and the Delicious API provides an abundance of topical data via jQuery tag feeds.

In this post I will show you how to use LINQ to XML to query the Delicious API, display that data in a table, apply the quickSearch plugin to that table, work around a problem that arises when using quickSearch with ASP.NET, and lay the groundwork for a “no results” state.

Working with the Delicious API

The Delicious APIs are fairly straightforward to work with. Their XML API takes the shape of an RSS feed containing items matching a query that you specify within the request URL. This is sometimes referred to as a RESTful API.

For example:

That request would return an RSS document describing the 25 most recent items appearing on the “popular” list for the jQuery tag. The actual XML returned for each item would look something like this (slightly abridged):

<item>   <title>Rich IntelliSense for jQuery</title>   <pubDate>Wed, 29 Oct 2008 07:56:03 +0000</pubDate>   <link></link>   <category>jquery</category>   <category>ASP.NET</category> </item>

Now that we have a handle on how to request the data and what the data looks like, we can easily build a LINQ to XML expression to query the API.

Using LINQ to XML to query the API

If you’ve dealt with XPath for querying XML documents in the past, you’re going to love LINQ to XML. For example, these few lines of code are all that is required to execute the API request and extract a collection for databinding:

XDocument doc =    XDocument.Load("");   var query = from item in doc.Descendants("item")             select new             {               Title = item.Element("title").Value,               Link = item.Element("link").Value,               Tags = (from c in item.Elements("category")                       select c.Value).Take(5).ToList()             };

This code will execute the REST request and then extract an IEnumerable collection containing the titles, URLs, and up to five tags for each item returned by the API.

Presenting the result of the API call

Presenting the data is a fairly standard affair. For this example, I’m going to use a table to display the results.

One detail we must attend to is that our table is rendered with a <tbody> element. Otherwise, it will be difficult to prevent the filtering functionality from applying to the table header as well.

To maintain the necessary control over the rendered HTML, let’s use a Repeater:

<asp:Repeater runat="server" ID="DeliciousItems">   <HeaderTemplate>     <table id="DeliciousItems">       <thead>         <tr>           <th>Item</th>           <th>Tags</th>         </tr>       </thead>       <tbody>   </HeaderTemplate>     <ItemTemplate>     <tr>       <td><a href='<%# Eval("Link") %>'><%# Eval("Title") %></a></td>       <td>         <asp:Repeater runat="server"                        datasource='<%# Eval("Tags") %>'>           <ItemTemplate><%# Container.DataItem %></ItemTemplate>             <SeparatorTemplate>, </SeparatorTemplate>         </asp:Repeater>       </td>     </tr>   </ItemTemplate>     <FooterTemplate>     </tbody> </table>   </FooterTemplate> </asp:Repeater>

The only tricky aspect of this is rendering the tags. Since those are contained in a List<string> nested inside each item’s Tags property, we need to nest a Repeater within the ItemTemplate to iterate over and display each item’s tags.

The trick to this is assigning the Tags property as the datasource for each of the nested Repeater controls. Using the SeparatorTemplate of a comma, we get a CSV rendering of the strings in the Tags List.

With a bit of CSS styling, our rendered table looks something like this:

What our rendered table looks like.

Using quickSearch to implement progressive search

Now that we’ve built an appropriate table of data, using quickSearch to implement the progressive search functionality is the easiest step:

$(document).ready(function() {   $("#DeliciousItems tbody tr").quicksearch({     // I don't care for the default label text.     labelText: 'Search: ',       // Anchor the search form to the table      //  and position it before the table     attached: '#DeliciousItems',     position: 'before',       // React quickly to keypresses.     delay: 100,       // Eliminate the "loader".     loaderText: '',   }); });

It should make sense now why rendering the <tbody> was important. It provides us an avenue to more easily construct a jQuery selector which correctly identifies the DOM elements that we intend to identify as searchable content.

Most of the options are self explanatory. This page on the author’s site contains more information about those settings and their defaults.

If you’re new to jQuery, the position option may give you trouble at first. Position has four possible values which match corresponding jQuery manipulation functions: prepend, append, before, and after. See those documentation pages for examples of how each option works, relative to the attached element.

Note: When quickSearch is attached to a table, avoid using prepend or append. Inserting its form inside a table’s markup will cause bad things to happen.

Now, if only that had worked

There’s one big problem with all of this: it doesn’t work!

You probably know that ASP.NET WebForms controls, such as the Repeater used above, must be enclosed within a <form runat=”server”> element. However, what you may not have known is that the quickSearch plugin renders itself in a form tag as well.

Unfortunately for us, HTML simply does not allow nested form elements. So, if you try to render the quickSearch interface within a WebForm, things don’t go well.

Some browsers handle this nested form problem gracefully, but others don’t. In any case, you certainly should not rely on the browser correcting this for you.

Making it work

In this simple example, we could attach quickSearch above the WebForm’s <form> element and it would work. That isn’t a good general solution though.

So, I updated the plugin to render a <div> instead of a <form>. Problem solved.

The modified version is included in the source download below. Feel free to use it in your own projects.

Displaying a “no results” message

A commenter on my last post made a good point, mentioning that the plugin lacks support a “no results” message when your search string filters all elements.

By adding an onAfter event handler, we can easily add that functionality ourselves:

$("#DeliciousItems tbody tr").quicksearch({   labelText: 'Search: ',   attached: '#DeliciousItems',   position: 'before',   delay: 100,   loaderText: '',   onAfter: function() {     if ($('#DeliciousItems tbody tr:visible').length == 0) {       // No Items.  Do something fancy here.     }   } });

I’ll leave the presentation specifics up to you. Just don’t use <blink>!

Conclusion: worth the effort

When applied to the appropriate situation, this real-time filtering technique is very compelling. Your users will absolutely love it.

Also be sure to check out Rick Strahl’s recent post on highlighting search matches, instead of filtering them.

If you have a Delicious account, why not take a few seconds and save this post to Delicious. Maybe we can get this post on the popular list used in the demo!




Originally posted at Encosia. If you’re reading this elsewhere, come on over and see the original.

Use jQuery and quickSearch to interactively search any data

Convert Videos with Free, Powerful Automen [Featured Windows Download]

Windows only: Convert videos from DVD or downloads into the format and size you like with Automen, a simple but powerful tool that’s small, free, and relatively easy to use. I say “relatively” compared to Mencoder, the command-line utility it provides a user interface for. You will have to edit the program’s INI configuration file in Notepad to get it working, so if drag-and-drop is more your speed it might not be right for you. You can choose from a variety of input and output formats (including XVID, FLV, WMV, and MP4), specify the output dimensions and even target file size, batch-process multiple videos and the software will take full advantage of multi-core processors to speed up encoding. For alternative tools, check out our top 10 free video rippers, encoders, and converters. Automen is a free download for Windows.

Ubuntu 8.10 Released, Includes Bootable USB Maker [Featured Download]

Ubuntu 8.10, the “Intrepid Ibex” release of the free, open-source Linux distribution, is officially out and available for download. This release doesn’t bring much huge or startlingly new to Ubuntu, but does smooth out some rough edges and improves the Wi-Fi, 3G, and portability experience. Check out our full screenshot tour of Intrepid Ibex to see what’s inside, and if your ISO downloads or upgrades are going slow today, read up on upgrading using BitTorrent or grabbing updates and ISOs from a mirror server. There’s also one or two new tools we didn’t catch earlier this month in the final release, which we’ll peek at below. Ubuntu 8.10 is a free download; it can run as a live CD or install on most Intel-based systems.

Ubuntu 8.10 includes a simple, working tool that puts a bootable Ubuntu system on a memory stick and lets you use persistent space on it to store settings and documents—in other words, keep a real Home folder there. I really wish, however, that you didn't have to download an Ubuntu ISO to make the disk, or that it could at least point you to a list of mirrors to find one on. In a perfect world, it would just create your USB disk from your current system, removing any specific hardware references and the like. As it is, though, it's a pretty handy tool for any spare thumb drives you've got.

Also new in the release candidate and final versions of 8.10 is a “System Cleaner” applet. I couldn’t dirty my brand-new desktop quick enough to give a good screenshot, but the Cleaner will apparently show any unneeded and abandoned software packages hanging around your system, and will also alert you to bad or leftover lines in your /etc/fstab (drive configuration), /etc/X11/xorg.conf (display and device manager), and all the other files you want to back up before messing with. If it works as promised, it’s a pretty good step toward that “for humans” slogan the distro touts.

Tell us your impressions of the final Intrepid Ibex in the comments.

#69- Gadget Station (Pt. 12)

Download Low Resolution
Download High Resolution

Well I finally made it to the finish line. This episode covers the hinge installation, pegging the tenons in the doors, making custom ebony handles, and finishing. I end the video with a justification of my design.

If you are interested in the Gripper system I showed for cutting small parts, you can pick one up in our Store. And if you are looking for the finishing DVD I mentioned, you can find that right here.

Gadget Station (Pt. 1)
Gadget Station (Pt. 2)
Gadget Station (Pt. 3)
Gadget Station (Pt. 4)
Gadget Station (Pt. 5)
Gadget Station (Pt. 6)
Gadget Station (Pt. 7)
Gadget Station (Pt. 8)
Gadget Station (Pt. 9)
Gadget Station (Pt. 10)
Gadget Station (Pt. 11)

Related Posts

Save Money on MP3 Purchases (or Find Them for Free) [How To]

The Macworld blog offers a few tips on doing comparison shopping between the major MP3 music stores. With Wal-Mart having recently slash prices on their online music tracks, the author recommends Safari uses create a web clip of the store’s Top Albums page and use a dashboard widget to search both the iTunes and Amazon store. There are a handful of other worthy links worth checking, including feeds of iTunes deals and free tracks, but the true discount is finding music for free. Read on for a few humble suggestions on doing that.

Find your tunes on the web

Our own Adam Pash has written the book on comprehensive web searching for a free album or song across the web’s many and varied sites. From music blog aggregator Hype Machine to straight-up MP3 searches with BeeMP3, if you can't find it on one of those sites, you've got a tried and true friend: A Google search that returns MP3s in open directories. Here's the string—just replace the "Album" and "Artist" and the like with your intended find:

-inurl:(htm|html|php) intitle:”index of” +”last modified” +”parent directory” +description +size +(wma|mp3) “artist|album|track|etc”

Grab it from a friend

If your friend’s just blatantly insisting that you check out this new album that’s going to blow your mind, you could always just ask him to share his MP3s through a share-friendly online storage serviceunless that friend bought their album off the iTunes store. If they can bring an iPod loaded with the tracks to your crib, you can copy music from iPod to computer, no matter what model they’re rocking. If there’s a distance factor, try having them install and share tracks with Mojo. The software has its quirks, but it often gets the job done. If they’re DRM-protected tracks, you might try doubleTwist or DVDneXtCopy’s faux-CD-burner. Those without legit access to an iTunes-bought track, though, will likely have to beg a friend to burn a CD, and then import it with a bit of audio quality loss.

Grab the audio from a video

Bands want to see their songs promoted, so they take their show on tour, do press interviews, and, more than that, make videos for their singles. If you’re looking for just such a song, why not use the audio that’s already floating around for free? Free web tools like Vixy and VidToMP3 automatically grab tracks from YouTube or other video URLs. Want a bit more control over audio quality and track format? Try reader Matt’s suggested method for recording YouTube music videos to MP3.

Update: Finally, as Coldmiser points out, your local library, especially in a larger metropolitan area, often has a pretty decent selection of CDs for borrowing and, if you’re cool with it, importing to your collection.

How do you save money, or search for deals, when you’re actually buying MP3s? What tools do you use to check whether a song or album is available free before dropping the cash? Tell us your techniques in the comments.

323 Small Table Project Part 1

A while back I built a small table that was originally intended for my son to use.  But it hasn't made it in his room yet.

This project was built in a single day and with materials I picked up at my local home center.  It's made entirely of No.2 common pine and a pre-laminated board.  Total cost, under $30. 

It’s a quick build and a great way to spend sometime in the shop just refining some skills or making new ones depending on how you build it.

This is part 1 of what will be a 4 or 5 part series each Wednesday.  Also, you may have noticed there's an audio only version of today's episode too.  Just trying a little something for those of you who like the audio shows also!  Let me know how it goes.

Next Wednesday, November 5 another LIVE WTO is happening!!  More information to follow!

Hendrik's back in November and we're taking your questions on table saws.  Whether it's regarding setting up, safety or cutting, get your questions in early. 

Also, if you'd like to enter for free schwag, have a comment, question or suggestion drop me a line at, head over to the website where you can also leave your comments, or you can leave a voicemail at 231 354-2338. - Helping You Make Wood Work

To download directly to your computer Right Click on direct download, choose "Save Target as"

Silverlight Toolkit Overview and Samples

Controls are where it’s at these days in the programming world. By using them you maximize re-use, enhance productivity and avoid building custom functionality. Plus, when you need a control to do something different you can always extend it rather than writing everything from scratch.

If you’ve used ASP.NET AJAX then you’ve likely used controls from toolkits such as the ASP.NET AJAX Control Toolkit in your applications. Microsoft has also released a Silverlight Toolkit with new controls and functionality that can be used in Silverlight 2 applications. The controls are grouped into “quality bands” with the existing controls currently fitting into either the “Preview” or “Stable” bands. Additional information about quality bands and the toolkit controls can be found on Shawn Burke’s blog.

Controls included in the Silverlight Toolkit include:

  • AutoCompleteBox
  • ButtonSpinner
  • Chart
  • DockPanel
  • Expander
  • HeaderedItemControl
  • HeaderedContentControl
  • ImplicitStyleManager
  • Label
  • NumericUpDown
  • TreeView
  • ViewBox
  • WrapPanel

The new controls live in the Microsoft.Windows.Controls.dll assembly which contains several namespaces such as Microsoft.Windows.Controls (where most of the controls live) and Microsoft.Windows.Controls.DataVisualization.Charting (where the charting control and related classes live). To get started using them you’ll need to reference the Microsoft.Windows.Controls assembly provided in the toolkit and then add the controls to your Visual Studio 2008 Toolbox by right-clicking on it and selecting “Choose Items”. Select the Silverlight Components tab, browse to the assembly and then check the checkbox next to the controls you’d like to add and then drag them into a Silverlight 2 XAML file. This will add the proper namespace onto the UserControl root element as shown next:


In this post I’ll discuss a few of the new controls that I personally find quite useful and show what they’re are capable of doing. Future posts will drill into different controls and demonstrate additional details about how they can be used.

Managing Silverlight Styles with ImplicitStyleManager

In a previous post I wrote about how styles can be defined and assigned to controls. While the default technique of defining and applying styles works, it certainly can be a pain to add Style=”{StaticResource YourStyleKey}” to all of the controls needing to pick-up a specific style in an application. WPF provides a way to “implicitly” apply styles to controls but this functionality isn’t available in Silverlight 2 unfortunately. Enter the ImplicitStyleManager provided by the Silverlight Toolkit. By using ImplicitStyleManager styles that target a specific control type can be applied without manually adding a Style attribute to each control. The class lives in the Microsoft.Windows.Controls.Theming namespace (Microsoft.Windows.Controls assembly) which needs to be referenced in the XAML file as shown next:

xmlns:theming="clr-namespace:Microsoft.Windows.Controls.Theming;assembly=Microsoft.Windows.Controls.Theming" >

Here’s an example of using ImplicitStyleManager within a control that has styles defined locally within its Resources section:


This example applies the styles to the appropriate controls (a Button and a TextBox in this case) automatically. The theming:ImplicitStyleManager.ApplyMode attribute makes this possible. Looking at the control definitions in the StackPanel you’ll see that no Style attribute is added. Instead, the styles are “implicitly” applied based on the Style element’s TargetType. You may also note that no x:Key is defined on the Style elements since it’s not needed.

ImplicitStyleManager can also be used to apply styles defined in a theme file (a XAML file containing a ResourceDictionary section) as shown next:


A portion of the CustomTheme.xaml file referenced by the code above is shown next:


WP Like Button Plugin by Free WordPress Templates