.Net, ASP.NET, Programming, Regular Expressions, VB.NET, Visual Studio 2010, Web Development

Regular Expressions in .NET to Surround but not Replace Text Matches

ASP.NET offers strong support for regular expressions in the System.Text.RegularExpressions Namespace. This is great since regular expressions are essential if you want to do anything beyond basic text manipulations and searches.

You can read more about regular expression support in ASP.NET on the official MSDN page. The MSDN site also includes a few good getting started examples if you are interested.

The Problem

Recently I found myself facing an interesting task: I was building a simple search form which consisted of a text area and submit button on a Web page. The desired behavior was as follows:

  1. Users could enter a partial term into the text area and then click the submit button to search for that partial text match.
  2. The codebehind would search through an MS SQL Server database to find the partial matches
  3. The codebehind would render the search results into a GridView control with the partial match text highlighted with a yellow background color

In theory putting this together is quite simple. The catch was figuring out how to highlight the partial text that the user searched for in the database results without changing the capitalization or other formatting.

For example if the user searched for the term EXAMPLe TexT (notice the crazy capitalization), then the data results should highlight the correct results in the search result output using the capitalization/formatting found in the database. Or more simply: the results should not depend on the user-entered search term, but should show the original text from the database surrounded by HTML markup tags. So no matter what strange capitalization the user entered, the search results should be properly capitalized and highlighted.

Continue reading “Regular Expressions in .NET to Surround but not Replace Text Matches”

.Net, ASP.NET, DropDownList, Programming, Visual Studio 2010, Web Development

Using an XMLDataSource with a DropDownList Control

If you work a lot with ASP.NET then it’s likely that at some point or another you will ask yourself how to hook up an XML Data Source with a DropDownList control.

This just makes sense if you want to manage your drop-downs from a file rather than from a database, and carries a range of advantages. For example, not having to go through a DBA to update a simple DropDownList item would be a good reason in my books.

Continue reading “Using an XMLDataSource with a DropDownList Control”

.Net, ASP.NET, IDE, Programming, Software, VB.NET, Visual Studio 2010, Web Development, WebForms

Use RAD with Visual Studio WebForms to Programmatically Query a SQLDataSource Control from Custom Code

Rapid Application Development (RAD) offers huge advantages to developers under time constraints looking to get an application released as quickly as possible. Visual Studio 2010’s WebForms is a great environment to use when looking at possible RAD solutions.

In this article I will cover the issue of using RAD with custom code to speed up writing database connections and queries. This is part of my series of articles investigating ASP.NET and Visual Studio 2010.

Continue reading “Use RAD with Visual Studio WebForms to Programmatically Query a SQLDataSource Control from Custom Code”