PDA

View Full Version : Controlling Dropdownlist Width???


Punkcrib
10-10-2007, 03:57 PM
Hello. I have 3 drop down lists that pull info from a DB. When the 1st is changed, the 2nd is populated, and when the 2nd is changed the 3rd is populated.

What I want to do is set all 3 DDL's to be the same width (the width of the longest one, whichever it may be).

I've written this script to check & set the lengths, but for some reason it always sets the lengths to "0":

Private Function DDLSize()
Dim d1 As Integer
Dim d2 As Integer
Dim d3 As Integer
Dim df As Integer

d1 = Me.DropDownList1.Width.Value
d2 = Me.DropDownList2.Width.Value
d3 = Me.DropDownList3.Width.Value
df = d1

If d2 > df Then
df = d2
End If
If d3 > df Then
df = d3
End If

Me.DropDownList1.Width = df
Me.DropDownList2.Width = df
Me.DropDownList3.Width = df
End Function

Can anyone tell me why this happens? My DDL's don't show up when I load the page because their size is being set to "0". If I manually enter a number in the last 3 lines of code (Me.DropDownList1.Width = "50") it works fine.

Why is it pulling "0" as the length of "Me.DropDownList1.Width.Value"???
This method is called after the data is binded, so I don't get it.

vinyl-junkie
10-11-2007, 03:00 AM
You can control the width of your list using the ListWidth property. This page (http://www.codeproject.com/aspnet/MultiSelectDropdownList.asp) gives an example of how to do that.

Punkcrib
10-12-2007, 10:10 PM
Thanks for the reply. However, ListWidth isn't a valid property of DropDownList. That must be a special property of that user control he created.

This is just weird though because if I do "Me.DropDownList1.Width = "20"" then it works fine. but when I try to get the width by using "Me.DropDownList1.Width.Value", it gives me a "0".

What could be causing this and how do I avoid it?