Click here to Skip to main content
Licence 
First Posted 9 Sep 2005
Views 94,537
Downloads 1,347
Bookmarked 22 times

Finally a Horizontal Scroll Bar List Box in ASP.NET!

By lintom | 9 Sep 2005
Implementing a horizontal scroll bar ListBox in ASP.NET.
6 votes, 35.3%
1
2 votes, 11.8%
2

3
4 votes, 23.5%
4
5 votes, 29.4%
5
2.77/5 - 17 votes
μ 2.77, σa 3.09 [?]

List Box with Horizontal Scroll Bar

Introduction

Have you ever imagined putting a horizontal scroll bar in a list box? As we are living in a high speed internet world, everybody wants their web application to look exactly similar to Windows applications and this article will explain how easily we can create a horizontal scroll bar using ASP.NET.

Problem

See the image given below. You have a list box which is supposed to hold a long text and the width won't fit into the listbox's width.

List Box with Horizontal Scroll Bar

Have you ever thought about changing a small property to change the style to show a horizontal scroll bar?

There is nothing like that available in ASP.NET.

Easy Way

We can put this list box inside a DIV and set the style for DIV to overflow which will automatically show the scroll bar whenever necessary.

Your aspx page has the following DIV:

<div id='hello' style="Z-INDEX: 102; LEFT: 13px; OVERFLOW: 
            auto; WIDTH: 247px; POSITION: absolute; TOP: 62px; HEIGHT: 134px" >

Important style you need to note is:

OVERFLOW: auto

inside the style element.

Now you can put your asp:listbox inside the DIV definition. Inside your code behind class' page_load function, you need to define the width and height of the list box properly, so that it won't overflow with the DIV.

Server side code looks as given below:

private void Page_Load(object sender, System.EventArgs e)
{
    if (!IsPostBack)
    {
        //Load all items in the list box.
        int nItem = Convert.ToInt32(ListBox1.Items.Count * 17);
        ListBox1.Height = nItem; //Set height depends on the font size.
        ListBox1.Width = 800; //This will ensure the list item won't be shrinked!
    }
}

Points of Interest

Nobody likes this way of implementing this. But as long as this meets the business requirements, everybody will be happy.

History

  • August.22.2005 - version 1.0.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

lintom

Software Developer

United States United States

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalnot working [modified] PinmemberMember 38761241:14 7 Oct '08  
GeneralAwesome.. PinmemberRohan Murli11:07 7 Aug '08  
GeneralHorizontal ScrollBar on an ASP.NET listbox... PinmemberRaymond Glaser11:55 13 Jul '08  
GeneralAdvanced ListBox Component Pinmemberdanludwig5:34 21 Jun '07  
GeneralHeight Limit PinmemberManish Sharma7:38 6 Jun '07  
GeneralRe: Height Limit Pinmemberdanludwig8:32 16 Jun '07  
JokeScrollableListBox PinmemberEvyatar Ben-Shitrit9:57 15 Jun '06  
GeneralPocket PC IE Pinmembergot2shot10:19 1 Feb '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120209.1 | Last Updated 9 Sep 2005
Article Copyright 2005 by lintom
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid