Share via


ListBox.Rows Propiedad

Definición

Obtiene o establece el número de filas que se muestran en el control ListBox.

public:
 virtual property int Rows { int get(); void set(int value); };
[System.ComponentModel.Bindable(true)]
public virtual int Rows { get; set; }
public virtual int Rows { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Rows : int with get, set
member this.Rows : int with get, set
Public Overridable Property Rows As Integer

Valor de propiedad

Int32

Número de filas que se muestran en el control ListBox. El valor predeterminado es 4.

Atributos

Excepciones

El número especificado de filas es inferior a 1 o superior a 2000.

Ejemplos

En el ejemplo siguiente se muestra cómo usar la Rows propiedad para mostrar seis filas en el ListBox control .

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <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;
      }

   </script>

</head>
<body>

   <h3>ListBox Example</h3>

   <form id="form1" 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-Names="Verdana" 
           Font-Size="10pt" 
           runat="server"/>
        
   </form>

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

      Sub SubmitBtn_Click(sender As Object, e As EventArgs) 
         If ListBox1.SelectedIndex > -1 Then
            Label1.Text = "You chose: " & ListBox1.SelectedItem.Text
         End If
      End Sub

   </script>

</head>
<body>

   <h3>ListBox Example</h3>

   <form id="form1" 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-Names="Verdana" 
           Font-Size="10pt" 
           runat="server"/>
        
   </form>

</body>
</html>

Comentarios

Utilice la Rows propiedad para especificar el número de filas que se van a mostrar en el ListBox control.

Precaución

El número de filas debe estar entre uno y 2000. Los valores fuera de este intervalo generarán una excepción.

El valor de la Rows propiedad se almacena en estado de vista.

Se aplica a

Consulte también