Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

Drop Down List Item Width

Hey. I need to create a drop down box with a specific width, but the text of the list items expand past this width. Is there a way to set the list width & the List object width seperately? Also, I have some tough requirements, so I need to keep the width = 150 and I have to use a DDL. I just need to find a  way to expand the viewable text area of the drop down items. Thanks!

<asp:DropDownList ID="ddlQuestion" runat="server" Width="150px">
<asp:ListItem Text="" />
<asp:ListItem Text="What is your all-time favorite sports team?" />
<asp:ListItem Text="What is your father's middle name?" />
<asp:ListItem Text="What was your high school mascot?" />
<asp:ListItem Text="What is your spouse's middle name?" />
<asp:ListItem Text="What is your best friend's last name?" />
<asp:ListItem Text="What is your pet's name?" />
<asp:ListItem Text="What is your mother's maiden name?" />
1 Solution
Elvio Lujan.Net Senior DeveloperCommented:
>>Is there a way to set the list width & the List object width seperately?

and if the width asignes to the ddl is minor that the length of the items it'll assume the item width
JeepGeekinAuthor Commented:
Thansk Lem, but I am going to leave this open for other ideas.
I am willing to consider javascript or other client side solution for this. Seems like there be a solution for this. Even if it is a creative one. I'll bump up the points.
Jason ScolaroCommented:
Hi JeepGeekin,

I'm having a hard time finding an example of what I'm about to reference, but basically when this issue comes up, what you must do is create a TextBox, an Image (or <img), a Panel (or <div>), and a ListBox.  Like so:

This is generally used for a ComboBox look and feel, like here:  http://www.codeproject.com/aspnet/combobox.asp

Your implementation would change it so the TextBox is ReadOnly.

<asp:TextBox runat="server" id="TextBox1" Width="150px" /><img src="downarrow.gif" onclick="showPanel()" />
<div style="display:none;border:solid 1px #000">
    <asp:ListBox runat="server" id="ListBox1" Rows="5" Width="200px" />

Basically you're recreating the functionality of a DropDownList.  Hopefully that ComboBox article will be of some help.  Just trying to give you an idea of one way to solve this...
-- Jason
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Here is a link with some info on your issue: http://icant.co.uk/forreview/tamingselect/

>> Is there a way to set the list width & the List object width seperately?
No, unless u create a custom control which beahaves like a dropdownlist .. its not going to be easy .. is it really worth the effort .. u culd always show tooltip of the selected item .. remember dropdownlist's tooltip does not work .. so wu ill have to write javascript function to show the selecteditem as a "div" tag .. just like a tooltip ..

JeepGeekinAuthor Commented:
Thanks guys for all the posts. Jason's tip is what I was looking for.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now