ListBox.Rows 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定控制中顯示 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
屬性值
控制區顯示 ListBox 的列數。 預設值為 4。
- 屬性
例外狀況
指定的列數小於一列或大於2000。
範例
以下範例示範如何利用該 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 控制項中顯示的列數。
謹慎
行數必須介於一到2000之間。 超出此範圍的數值將觸發例外。
財產價值 Rows 會以視圖狀態儲存。