Category Archives: Databases

Parent-Child DropDownList Controls In ASP.NET Web Forms (VB.NET)

Some time ago I promised a formspring anon I would do a tutorial on parent / child DropDownList controls in ASP.NET Web Forms. At long last, I’m delivering. (From here on out, I will use “DropDownList” and “select list” interchangeably.)

Parent-child DropDownList controls means you have a parent, or main / master select list. Based on whatever selection is made in that first DropDownList, a second, “child” or “detail” select list is populated with relevant results.For example, if we had a database of cars, we might have a parent (master) DropDownList of manufacturers — Ford, Chevy, Toyota, etc. — and populate the child DropDownList with models from the selected manufacturer. So, if someone chose Ford in the parent select list, the child select list would automatically populate with choices such as Fusion, Mustang, Explorer, F-150, etc.

I’ll be demonstrating two different ways to accomplish this task, as well as a few variations on the first: First, binding with only SqlDataSource controls, which is by far the easiest way to proceed and will suffice for about 90 percent of applications; second, using code behind and CompareValidator controls, to cover all possible roadblocks.

Some notes before we proceed:

  • I’ll use the ZIP Code database I’ve been using for a while as the back-end data. I also have a separate table of USPS state codes I’m using as the parent data, to help illustrate that you can use several tables / data sources to fuel this solution, provided the keys that relate the data make sense to each data store. In other words, you can use a lot of different sources for your data, so long as the data is relational.
  • I’m going to use SQL Server, stored procedures and a connection string stored in my web.config file to access my data. I recognize that some people prefer to use SQL statements / LINQ and the like, or can only use Access / MySQL or other data stores. I really urge you to always use stored procedures, as they are way safer than inline SQL statements. As far as alternative data stores go, that should be a easy a fix as switching your code to use to the relevant ADO.NET ODBC classes, rather than the SQL Client classes.
  • This solution should work for ASP.NET versions 2.0 forward.

Continue reading

Hi Doug, “Sorting Your MySQL Results Set In PHP Using jQuery” is perfect for what I need, thanks.The cursor changes to an “I” beam rather than a hand when hovering over a column heading – can this be altered to show a hand for the clickable heading?

You can use CSS and the hover pseudoclass:

#sortedtable thead th:hover {
    cursor: pointer;

Ask me anything

I read your article about auto-hashtagging. Maybe you forgot when a to-be-tag is ending with a ‘.’ of ‘,’ or other punctuation…?

Seems that’s the case. Good catch! An easy fix is to simply run the input string through a regular expression that strips out the punctuation before exploding it into an array.

Ask me anything

Hi Doug, I saw your response to a person on Yahoo answers, It was probably a couple of years ago. I’m trying toget my hands on a Sap tool to practice on it on my own. You mentioned you were doing the same at that time. Do you still have it? Thanks

Sorry, I don’t recall this. I did have a client a while back who was interested in SAP but I don’t believe I ever followed through.

If you could provide a link to the question, it might help refresh my memory.

I don’t believe I’ve ever said I use pirated software, and I’d be surprised to see anything in which I offered to share pirated software. It’s possible I noted that stealing software was an option, but I have to believe that if I said that, I also said that doing so was legally and morally wrong. Again, a link to the question you’re referencing would clear things up for me.

For the record, I have often said — and stand by the statement — that it’s everyone’s right to make personal copies of software he has legally purchased, even if a EULA forbids personal copies; but I don’t believe it’s OK to distribute copy-restricted software in violation of license terms.

Ask me anything