This documentation is archived and is not being maintained.

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; }
/** @property */
public int get_Rows ()

/** @property */
public void set_Rows (int value)

public function get Rows () : int

public function set Rows (value : int)

Property Value

The number of rows displayed in the ListBox control. The default value is 4.

Exception typeCondition

ArgumentOutOfRangeException

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.

TopicLocation
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" %>
<html>
<head>

   <script language="C#" runat="server">

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

   </script>

</head>
<body>

   <h3>ListBox Example</h3>

   <form runat=server>

      <asp:ListBox id="ListBox1" 
           Rows="6"
           Width="100px"
           SelectionMode="Single" 
           runat="server">

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

      <asp:button id="Button1"
           Text="Submit" 
           OnClick="SubmitBtn_Click" 
           runat="server" />
        
      <asp:Label id="Label1" 
           Font-Name="Verdana" 
           Font-Size="10pt" 
           runat="server"/>
        
   </form>

</body>
</html>


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: