Adjusting the height of a ListBox (<select>)

Posted on 2007-07-25
Last Modified: 2010-12-03
I'm using the ListBox on my HTML-page.

<select size="4" name="DrawingsList" id="DrawingsList" style="height:100%;width:100%;" >
  <option value="vvv" >TTT</option>

The ListBox is putted into a DIV and should cover all the space inside the DIV. But the height of the ListBox is automatically rounded and made divisible by the font's height. So, the height is a bit incorrect.

In WinForms and Win32, I know, you can turn off the "Integral height" mode and get exactly sized ListBox.

How can I get exactly sized ListBox in HTML?

Thanks for a response!
Question by:alexf2
    LVL 7

    Expert Comment

    Try using the ASP.NET ListBox control instead of the HTML equivalent - this should give you exact control over the size
    LVL 7

    Expert Comment

    My mistake - looks like in the designer you can set the size, but when you run it, it automatically resizes!

    Author Comment

    Yes, I'm using
    <asp:ListBox ID="DrawingsList" runat="server"  DataSourceID="SqlDrawings" DataTextField="AssemblyName" DataValueField="AssemblyId" AutoPostBack="True" CssClass="DrawingsListClass" Height="100%" Width="100%"></asp:ListBox>

    I have tried to set the height by means of Width property of the asp:ListBox and by means of CSS. The result is the same: rounded "Integral height" is used.
    LVL 7

    Accepted Solution

    Take a look at this:

    I've just tried it out by creating a Custom Web Control using their technique and it seems to work! (In C#)
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now