YouTip LogoYouTip

Prop Webcontrol Listbox Rows

## ASP.NET Web Control: ListBox Rows Property The `Rows` property is a key attribute of the ASP.NET `ListBox` web control. It allows developers to define the number of items that are visible at one time within the list box without the user needing to scroll. --- ## Definition and Usage The `Rows` property gets or sets the number of visible rows in a `ListBox` control. * **Default Behavior:** If this property is not set, the browser determines the default height of the list box (typically displaying 4 rows by default in most browsers). * **Scrollbars:** If the `ListBox` contains more items than the number specified in the `Rows` property, a vertical scrollbar will automatically appear to allow users to scroll through the remaining items. --- ## Syntax ```xml ``` ### Property Values | Attribute Value | Description | | :--- | :--- | | `num` | An integer that specifies the number of visible rows in the `ListBox` control. The value must be greater than or equal to `1`. | --- ## Code Example The following example demonstrates how to set the `Rows` property of a `ListBox` control to display exactly 5 items at once. ```xml
Item 1 Item 2 Item 3 Item 4 Item 5 Item 6 Item 7
``` ### How it behaves: * The `ListBox` will render with a height sufficient to display exactly 5 items (`Item 1` through `Item 5`). * Because there are 7 items in total, a vertical scrollbar will automatically be rendered so the user can scroll down to select `Item 6` and `Item 7`. --- ## Technical Considerations 1. **Rendering in HTML:** When compiled and sent to the client browser, the ASP.NET `` control renders as an HTML `` element. The `Rows` property directly maps to the HTML `size` attribute. 2. **Layout and CSS:** While the `Rows` property is excellent for setting a row-based height, you can also control the physical height of the control using CSS (`height` property) or the control's `Height` property. However, using `Rows` is highly recommended to ensure that list items do not get vertically cut off mid-line. 3. **Selection Mode:** The `Rows` property works independently of whether the `SelectionMode` is set to `Single` or `Multiple`.
← Prop Webcontrol Listbox SelectProp Webcontrol Listcontrol Va β†’