Freigeben über


ListBox.Rows-Eigenschaft

Ruft die Anzahl der Zeilen ab, die im ListBox-Steuerelement angezeigt werden, oder legt diese fest.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Public Overridable Property Rows As Integer
'Usage
Dim instance As ListBox
Dim value As Integer

value = instance.Rows

instance.Rows = value
public virtual int Rows { get; set; }
public:
virtual property int Rows {
    int get ();
    void set (int value);
}
/** @property */
public int get_Rows ()

/** @property */
public void set_Rows (int value)
public function get Rows () : int

public function set Rows (value : int)

Eigenschaftenwert

Die Anzahl der im ListBox-Steuerelement angezeigten Zeilen. Der Standardwert ist 4.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentOutOfRangeException

Die angegebene Zeilenanzahl ist kleiner als 1 oder größer als 2000.

Hinweise

Mit der Rows-Eigenschaft können Sie die Anzahl der Zeilen angeben, die im ListBox-Steuerelement angezeigt werden sollen.

Warnung

Die Zeilenanzahl muss zwischen 1 und 2000 liegen. Wenn ein Wert außerhalb dieses Bereichs angegeben wird, löst dies eine Ausnahme aus.

Der Wert der Rows-Eigenschaft wird im Ansichtszustand gespeichert.

Thema Position
Gewusst wie: Hinzufügen von ListBox-Webserversteuerelementen zu einer Web Forms-Seite Erstellen von ASP.NET-Webanwendungen

Beispiel

Das folgende Beispiel veranschaulicht, wie mit der Rows-Eigenschaft sechs Zeilen im ListBox-Steuerelement angezeigt werden.

<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>

   <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 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>
<%@ 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>
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
<head>

   <script language="JSCRIPT" runat="server">

      function SubmitBtn_Click(sender : Object, e : EventArgs) {
         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>

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ListBox-Klasse
ListBox-Member
System.Web.UI.WebControls-Namespace

Weitere Ressourcen

ListBox-Webserver-Steuerelement