ListBox.Rows 속성

정의

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

속성 값

Int32

ListBox 컨트롤에 표시할 행의 수입니다. 기본값은 4입니다.

특성

예외

지정된 행의 수가 1보다 작거나 2000보다 큰 경우

예제

다음 예제에서는 컨트롤에 6 개의 행을 Rows 표시 하는 속성을 사용 하는 방법을 보여 줍니다 ListBox .

<%@ 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>

설명

컨트롤에 Rows 표시 ListBox 할 행 수를 지정하려면 이 속성을 사용합니다.

주의

행 수는 1에서 2000 사이여야 합니다. 이 범위를 벗어난 값은 예외를 발생합니다.

값을 Rows 속성은 뷰 상태에 저장 됩니다.

적용 대상

추가 정보