Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

ListBox.Rows Property

Gets or sets the number of rows displayed in the ListBox control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
public virtual int Rows { get; set; }
<asp:ListBox Rows="Int32" />

Property Value

Type: System.Int32
The number of rows displayed in the ListBox control. The default value is 4.

The specified number of rows is less than one or greater than 2000.

Use the Rows property to specify the number of rows to display in the ListBox control.

Caution noteCaution

The number of rows must be between one and 2000. Values outside of this range will raise an exception.

The value of the Rows property is stored in view state.

How to: Add ListBox Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add ListBox Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications

The following example demonstrates how to use the Rows property to display six rows in the ListBox control.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>ListBox Example</title>
<script language="C#" runat="server">

      void SubmitBtn_Click(Object sender, EventArgs e) 
         if (ListBox1.SelectedIndex > -1)
            Label1.Text="You chose: " + ListBox1.SelectedItem.Text;



   <h3>ListBox Example</h3>

   <form id="form1" runat="server">

      <asp:ListBox id="ListBox1" 

         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>


      <asp:button id="Button1"
           runat="server" />

      <asp:Label id="Label1" 



.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.