Asp.Net Multi-Column DropDownList 
Without A 3rd Party Control


A search on the topic will usually bring up this page in the top results: 1432282.aspx

I've worked on this for hours and hours. The link above is somewhat helpful, but the queries shown do not actually return fixed length columns, or at least they didn't for me using MS Access. Here is what I did to get columns in a dropdownlist (multi-column dropdown) without using a third party control. Put this in your query:

[part_number] & String(1 + (20 - len(part_number)), ""."") & [Description] As [Part]

This makes fixed length columns by taking into account the length of the first column, rather than just adding a fixed number of characters at the end of it! Note: I think this will throw an error if the first column has a length of more than what you are subtracting out, so you may want to take that into account or cap the length of the first field in your query.

The next thing you have to do is add this to your code:

DropDownList1.DataSource = dt0

        For Each item As ListItem In DropDownList1.Items
            item.Text = item.Text.Replace(".", " ")
            item.Text = HttpUtility.HtmlDecode(item.Text)

So you are adding a fixed number of periods, replacing them with a non-breaking space, and using HtmlDecode to make them render in a browser.

The last thing you need to do is use a fixed length font. It will work without that, but the columns don't line up perfectly. It still looks better than what the above link gave me, though.

This is a straight dropdown list with 2 columns of information pulled from the database and using the above SQL query and a fixed length font:

I don't know how well it would scale on a dropdownlist with a large number of items, but it is very snapy on a normal sized dropdownlist.

Does anyone know of a way to do this using CSS instead of non-breaking spaces?

Extra points for someone that can do that!