ListBox.Rows Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the number of rows displayed in the ListBox control.
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
Property Value
The number of rows displayed in the ListBox control. The default value is 4
.
- Attributes
Exceptions
The specified number of rows is less than one or greater than 2000.
Examples
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"
"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>
Remarks
Use the Rows property to specify the number of rows to display in the ListBox control.
Caution
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.
Applies to
See also
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示