Drop Down List Item Width

Posted on 2006-03-28
Last Modified: 2008-02-01
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?" />
Question by:JeepGeekin
    LVL 17

    Expert Comment

    >>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

    Author Comment

    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.
    LVL 22

    Accepted Solution

    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:

    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
    LVL 5

    Expert Comment

    Here is a link with some info on your issue:

    LVL 26

    Expert Comment

    >> 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 ..


    Author Comment

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

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now