Got an ASP.NET site backed by C#. It’s an internal page that lists what physical servers our virtual machines are on. The list is quite long, so what I want is to be able to filter down the list as the user types into a textbox. For example, let’s say we have three servers named “texas”, “newyork” and “nevada”. If the user types the letter “n” into the specified textbox, the list will (preferably client-side, without postback) remove texas from the list. Further, when the user gets as far as entering “nev”, newyork gets filtered out too, leaving us just with “nevada”.
I don’t believe this kind of functionality exists for the default GridView. At least, I can’t find anything about it anyway, not for a web form.
The alternative “well I guess it works” solution I can think of, since it’s an internal site and the page will be used maybe like a couple of times a week at most, is to postback on text input, and throw the partially entered string against the database and rebind the table based on the returned results. So that by the time we have typed in “nev”, we’ve made 3 postbacks and 3 database queries. I’m fairly certain that would be easy to pull off, and since it’s a completely intranet site with basic to no security needs only used by a handful of people, I don’t need to worry about someone just hammering the keyboard to purposely try and call the server a billion times. I realize that’s a horrible idea in a real open world scenario, but for our needs I don’t see it being a problem.
I’m open to any kind of solution that will help me accomplish the same effect, even if it’s something other than a GridView.
I just came across an example of doing this in Rx (Reactive Extensions). It uses the .Throttle() to prevent it from posting with every keypress. So you can throttle to update at most every second or ever so often. The full example is exercise 5 on page 18 in this PDF tutorial, http://go.microsoft.com/fwlink/?LinkId=208528 . (Rx home page)
It’s too much to copy and paste here, but the tutorial has the full example. The gist of it is that each key press is processed as a ‘sequence’. Each item in the sequence is then processed by an event. In your case the action performed on each change would be filtering the GridView based on the current value of the textbox (and again the Throttle() would be the key to keep fast typers from updating it too often.
As far as posting back each time I would use AJAX.NET in this situation to create a smoother UI. AJAX can do a postback to the server to get new data, etc but without the users entire page refreshing. This would be ideal. There are some simple AJAX.NET tutorials. There are only a few ui controls so it does not take too long to get the feel for it.
Edit: If mini-postbacks with ajax.net is not fast enough, rx works with client-side javascript as well. http://channel9.msdn.com/Blogs/Charles/Introducing-RxJS-Reactive-Extensions-for-JavaScript