BulletedList.DisplayMode 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置 BulletedList 控件中的列表内容的显示模式。
public:
virtual property System::Web::UI::WebControls::BulletedListDisplayMode DisplayMode { System::Web::UI::WebControls::BulletedListDisplayMode get(); void set(System::Web::UI::WebControls::BulletedListDisplayMode value); };
public virtual System.Web.UI.WebControls.BulletedListDisplayMode DisplayMode { get; set; }
member this.DisplayMode : System.Web.UI.WebControls.BulletedListDisplayMode with get, set
Public Overridable Property DisplayMode As BulletedListDisplayMode
属性值
BulletedListDisplayMode 值之一。 默认值为 Text。
例外
指定的类型不是 BulletedListDisplayMode 值之一。
示例
下面的代码示例演示如何创建控件 BulletedList 并设置 DisplayMode 属性。 控件 ListBox 使用 BulletedListDisplayMode 枚举值填充。 列表项内容的格式会根据用户从列表框中选择的显示模式而更改。
<%@ 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>DisplayMode Example</title>
<script runat="server">
void Index_Changed(object sender, System.EventArgs e)
{
// Change the message displayed, based on
// the display mode selected from the list box.
if (DisplayModeListBox.SelectedIndex > -1)
{
Message1.Text = "You chose: " + DisplayModeListBox.SelectedItem.Text;
}
// Change the display mode, based on
// the mode selected from the list box.
switch (DisplayModeListBox.SelectedIndex)
{
case 0:
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.Text;
Message2.Text = "";
break;
case 1:
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.HyperLink;
// Opens a new browser window to display the page linked to.
ItemsBulletedList.Target = "_blank";
Message2.Text = "";
break;
case 2:
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.LinkButton;
break;
default:
throw new Exception("You did not select a valid display mode.");
break;
}
}
void ItemsBulletedList_Click(object sender, System.Web.UI.WebControls.BulletedListEventArgs e)
{
// Change the message displayed, based on the index
// of the bulletedlist list item that was clicked.
switch (e.Index)
{
case 0:
Message2.Text = "You clicked list item 1.";
break;
case 1:
Message2.Text = "You clicked list item 2.";
break;
case 2:
Message2.Text = "You clicked list item 3.";
break;
default:
throw new Exception("You did not click a valid list item.");
break;
}
}
</script>
</head>
<body>
<h3>DisplayMode Example</h3>
<form id="form1" runat="server">
<h3>BulletedListDisplayMode Example</h3>
<p>
<asp:BulletedList id="ItemsBulletedList"
BulletStyle="Disc"
DisplayMode="Text"
OnClick="ItemsBulletedList_Click"
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></p>
<hr />
<h4>Select from the list to change the display mode:</h4>
<asp:ListBox id="DisplayModeListBox"
Rows="1"
SelectionMode="Single"
AutoPostBack="True"
OnSelectedIndexChanged="Index_Changed"
runat="server">
<asp:ListItem>Text</asp:ListItem>
<asp:ListItem>Hyperlink</asp:ListItem>
<asp:ListItem>LinkButton</asp:ListItem>
</asp:ListBox>
<asp:Label id="Message1"
runat="server"
AssociatedControlID="DisplayModeListBox"/><br /><br />
<asp:Label id="Message2"
runat="server"
AssociatedControlID="DisplayModeListBox"/>
</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>DisplayMode Example</title>
<script runat="server">
Sub Index_Changed(ByVal sender As Object, ByVal e As System.EventArgs)
' Change the message displayed, based on
' the display mode selected from the list box.
If DisplayModeListBox.SelectedIndex > -1 Then
Message1.Text = "You chose: " & DisplayModeListBox.SelectedItem.Text
End If
' Change the display mode, based on
' the mode selected from the list box.
Select Case (DisplayModeListBox.SelectedIndex)
Case 0
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.Text
Message2.Text = ""
Case 1
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.HyperLink
' Opens a new browser window to display the page linked to.
ItemsBulletedList.Target = "_blank"
Message2.Text = ""
Case 2
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.LinkButton
Case Else
Throw New Exception("You did not select a valid display mode.")
End Select
End Sub
Sub ItemsBulletedList_Click(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.BulletedListEventArgs)
' Change the message displayed, based on the index
' of the bulletedlist list item that was clicked.
Select Case (e.Index)
Case 0
Message2.Text = "You clicked list item 1."
Case 1
Message2.Text = "You clicked list item 2."
Case 2
Message2.Text = "You clicked list item 3."
Case Else
Throw New Exception("You did not click a valid list item.")
End Select
End Sub
</script>
</head>
<body>
<h3>DisplayMode Example</h3>
<form id="form1" runat="server">
<h3>BulletedListDisplayMode Example</h3>
<p>
<asp:BulletedList id="ItemsBulletedList"
BulletStyle="Disc"
DisplayMode="Text"
OnClick="ItemsBulletedList_Click"
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></p>
<hr />
<h4>Select from the list to change the display mode:</h4>
<asp:ListBox id="DisplayModeListBox"
Rows="1"
SelectionMode="Single"
AutoPostBack="True"
OnSelectedIndexChanged="Index_Changed"
runat="server">
<asp:ListItem>Text</asp:ListItem>
<asp:ListItem>Hyperlink</asp:ListItem>
<asp:ListItem>LinkButton</asp:ListItem>
</asp:ListBox>
<asp:Label id="Message1"
runat="server"
AssociatedControlID="DisplayModeListBox"/><br /><br />
<asp:Label id="Message2"
runat="server"
AssociatedControlID="DisplayModeListBox"/>
</form>
</body>
</html>
注解
DisplayMode使用 属性指定要应用于控件中BulletedList列表项内容的显示行为。 属性 DisplayMode 是使用枚举值之一设置的 BulletedListDisplayMode 。 下表列出了可能的值。
值 | 显示为 |
---|---|
Text | 文本。 |
HyperLink | 链接。 |
LinkButton | 链接按钮。 |
值 HyperLink 允许将列表内容显示为超链接。 单击后,超链接将导航到 URL。 Value使用 属性指定超链接导航到的 URL。
字段 LinkButton 允许您将列表内容显示为链接。 BulletedList.Click单击链接按钮时,使用 事件发回服务器。
此属性的值存储在视图状态中。