BulletedList.FirstBulletNumber 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置排序 BulletedList 控件中列表项开始编号的值。
public:
virtual property int FirstBulletNumber { int get(); void set(int value); };
public virtual int FirstBulletNumber { get; set; }
member this.FirstBulletNumber : int with get, set
Public Overridable Property FirstBulletNumber As Integer
属性值
排序 BulletedList 控件中列表项开始编号的值。 默认为 1
。
示例
下面的代码示例演示如何创建控件 BulletedList 并设置 FirstBulletNumber 属性以指定开始对控件中的 BulletedList 列表项进行编号的值。 开始列表项编号的值会根据用户在文本框中输入的值而更改。
重要
此示例具有一个接受用户输入的文本框,这是一个潜在的安全威胁。 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。 有关详细信息,请参阅脚本侵入概述。
<%@ Page Language="C#" %>
<!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 runat="server">
<title>First Bullet Number Example</title>
<script runat="server">
void Index_Changed(object sender, System.EventArgs e)
{
// Set the starting number for the bulleted list.
ItemsBulletedList.FirstBulletNumber = Convert.ToInt32(StartValue.Text);
switch (BulletStylesListBox.SelectedIndex)
{
case 0:
ItemsBulletedList.BulletStyle = BulletStyle.Numbered;
break;
case 1:
ItemsBulletedList.BulletStyle = BulletStyle.LowerAlpha;
break;
case 2:
ItemsBulletedList.BulletStyle = BulletStyle.UpperAlpha;
break;
case 3:
ItemsBulletedList.BulletStyle = BulletStyle.LowerRoman;
break;
case 4:
ItemsBulletedList.BulletStyle = BulletStyle.UpperRoman;
break;
default:
throw new Exception("You did not select a valid bullet style");
break;
}
}
</script>
</head>
<body>
<h3>First Bullet Number Example</h3>
<form id="form1" runat="server">
<asp:BulletedList id="ItemsBulletedList"
BulletStyle="Disc"
DisplayMode="Text"
runat="server">
<asp:ListItem Value="http://www.cohowinery.com">Coho Winery</asp:ListItem>
<asp:ListItem Value="http://www.contoso.com">Contoso, Ltd.</asp:ListItem>
<asp:ListItem Value="http://www.tailspintoys.com">Tailspin Toys</asp:ListItem>
</asp:BulletedList>
<hr />
<h4>Enter the first number to start the list</h4>
<asp:TextBox id="StartValue"
Text="1"
runat="server">
</asp:TextBox><br />
<asp:RangeValidator id="Range1"
ControlToValidate="StartValue"
MinimumValue="1"
MaximumValue="32000"
Type="Integer"
ErrorMessage="Please enter a number greater than zero and less than 32,000."
runat="server">
</asp:RangeValidator><br />
<h4>Select a bullet type:</h4>
<asp:ListBox id="BulletStylesListBox"
SelectionMode="Single"
Rows="1"
AutoPostBack="True"
OnSelectedIndexChanged="Index_Changed"
CausesValidation="true"
runat="server" >
<asp:ListItem Value="Numbered">Numbered</asp:ListItem>
<asp:ListItem Value="LowerAlpha">LowerAlpha</asp:ListItem>
<asp:ListItem Value="UpperAlpha">UpperAlpha</asp:ListItem>
<asp:ListItem Value="LowerRoman">LowerRoman</asp:ListItem>
<asp:ListItem Value="UpperRoman">UpperRoman</asp:ListItem>
</asp:ListBox><br />
<hr />
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!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 runat="server">
<title>First Bullet Number Example</title>
<script runat="server">
Sub Index_Changed(ByVal sender As Object, ByVal e As System.EventArgs)
' Set the starting number for the bulleted list.
ItemsBulletedList.FirstBulletNumber = StartValue.Text
Select Case (BulletStylesListBox.SelectedIndex)
Case 0
ItemsBulletedList.BulletStyle = BulletStyle.Numbered
Case 1
ItemsBulletedList.BulletStyle = BulletStyle.LowerAlpha
Case 2
ItemsBulletedList.BulletStyle = BulletStyle.UpperAlpha
Case 3
ItemsBulletedList.BulletStyle = BulletStyle.LowerRoman
Case 4
ItemsBulletedList.BulletStyle = BulletStyle.UpperRoman
Case Else
Throw New Exception("You did not select a valid bullet style")
End Select
End Sub
</script>
</head>
<body>
<h3>First Bullet Number Example</h3>
<form id="form1" runat="server">
<asp:BulletedList id="ItemsBulletedList"
BulletStyle="Disc"
DisplayMode="Text"
runat="server">
<asp:ListItem Value="http://www.cohowinery.com">Coho Winery</asp:ListItem>
<asp:ListItem Value="http://www.contoso.com">Contoso, Ltd.</asp:ListItem>
<asp:ListItem Value="http://www.tailspintoys.com">Tailspin Toys</asp:ListItem>
</asp:BulletedList>
<hr />
<h4>Enter the first number to start the list</h4>
<asp:TextBox id="StartValue"
Text="1"
runat="server">
</asp:TextBox><br />
<asp:RangeValidator id="Range1"
ControlToValidate="StartValue"
MinimumValue="1"
MaximumValue="32000"
Type="Integer"
ErrorMessage="Please enter a number greater than zero and less than 32,000."
runat="server" >
</asp:RangeValidator><br />
<h4>Select a bullet type:</h4>
<asp:ListBox id="BulletStylesListBox"
SelectionMode="Single"
Rows="1"
AutoPostBack="True"
OnSelectedIndexChanged="Index_Changed"
CausesValidation="true"
runat="server" >
<asp:ListItem Value="Numbered">Numbered</asp:ListItem>
<asp:ListItem Value="LowerAlpha">LowerAlpha</asp:ListItem>
<asp:ListItem Value="UpperAlpha">UpperAlpha</asp:ListItem>
<asp:ListItem Value="LowerRoman">LowerRoman</asp:ListItem>
<asp:ListItem Value="UpperRoman">UpperRoman</asp:ListItem>
</asp:ListBox><br />
<hr />
</form>
</body>
</html>
注解
FirstBulletNumber使用 属性指定值,该值开始对有序BulletedList控件中的列表项进行编号。 如果BulletStyle属性设置为 Disc、Square、 Circle或 CustomImage 值,则忽略分配给 FirstBulletNumber 属性的值。 虽然 属性的值 FirstBulletNumber 是整数,但它并不总是导致项目符号呈现为数字。 例如,如果将 属性4
设置为 FirstBulletNumber 并将 属性设置为 BulletStyle 值 LowerAlpha,则第一个项目符号编号将呈现为小写 d。
此属性的值存储在视图状态中。