Export (0) Print
Expand All

BulletedList Class

Creates a control that generates a list of items in a bulleted format.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public class BulletedList : ListControl, IPostBackEventHandler
public class BulletedList extends ListControl implements IPostBackEventHandler
public class BulletedList extends ListControl implements IPostBackEventHandler
Not applicable.

Use the BulletedList control to create a list of items that are formatted with bullets. To specify the individual list items that you want to appear in a BulletedList control, place a ListItem object for each entry between the opening and closing tags of the BulletedList control.

To specify the bullet type to use to display list items in a BulletedList control, set the BulletStyle property to one of the bullet types that are defined by the BulletStyle enumeration. The following table lists the available bullet styles.

Bullet style

Description

NotSet

Not set.

Numbered

A number.

LowerAlpha

A lowercase letter.

UpperAlpha

An uppercase letter.

LowerRoman

A lowercase Roman numeral.

UpperRoman

An uppercase Roman numeral.

Disc

A filled circle.

Circle

An empty circle.

Square

A filled square.

CustomImage

A custom image.

Use the FirstBulletNumber property to specify the value that starts the numbering of list items in an ordered BulletedList control. The value that is assigned to the FirstBulletNumber property is ignored, if the BulletStyle property is set to the Disc, Square, Circle, or CustomImage field. If you set the BulletStyle property to the value of CustomImage to specify a custom image for the bullet, you must set the BulletImageUrl property also to specify the location of the image file.

To specify the display behavior of the list items in a BulletedList, set the DisplayMode property to one of the values that are defined by the BulletedListDisplayMode enumeration. The defined display behaviors are Text, HyperLink, and LinkButton.

When a hyperlink is clicked, it navigates to a URL. Use the Value property to specify the URL that a hyperlink navigates to. Use the Target property to specify the frame or window that displays the Web page that is navigated to when a hyperlink is clicked.

When the DisplayMode property is set to LinkButton, the BulletedList control displays list items as links that post back to the server when clicked. To programmatically control the actions that are performed when a link button is clicked, provide an event handler for the Click event. Note that the SelectedIndex and SelectedItem properties are inherited from the ListControl class and are not applicable to the BulletedList control. Use the event data of the BulletedListEventArgs class to determine the index of the link button in a BulletedList that was clicked.

The BulletedList control also supports data binding. To bind the BulletedList to a data source, you can use any of the provided data-binding mechanisms. For more information, see ASP.NET Data Binding.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

This section contains two code examples. The first code example demonstrates how to create a BulletedList control with list items that are formatted as link buttons. The second code example demonstrates how to create a BulletedList control using data binding to specify the list items.

The following code example demonstrates how to create a BulletedList control with list items that are formatted as link buttons. Text is displayed in a Label control when a list item is clicked.

<%@ 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>BulletedList Click Example</title>
<script runat="server">

        Sub ItemsBulletedList_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.BulletedListEventArgs)
            ' Change the message displayed in the label based on the index
            ' of the list item that was clicked.
            Select Case (e.Index)
                Case 0
                    Message.Text = "You clicked list item 1."
                Case 1
                    Message.Text = "You clicked list item 2."
                Case 2
                    Message.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>BulletedList Click Example</h3>

    <form id="form1" runat="server">
            
        <p>Click on an item in the list to raise the Click event.</p> 
        
        <asp:BulletedList id="ItemsBulletedList" 
            BulletStyle="Disc"
        DisplayMode="LinkButton" 
        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>
            
    <asp:Label id="Message" 
        Font-Size="12"
        Width="168px" 
        Font-Bold="True" 
        runat="server"
        AssociatedControlID="ItemsBulletedList"/>
              
   </form>

</body>
</html>

The following code example demonstrates how to create a BulletedList control using data binding to specify the list items. The list items are formatted as link buttons. Text is displayed in a Label control when a list item is clicked.

<%@ 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>BulletedList Class Data Binding Example</title>
<script runat="server">

        Sub ProductsBulletedList_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.BulletedListEventArgs)
            ' Change the message displayed in the label based on the index
            ' of the list item that was clicked.
            Select Case (e.Index)
                Case 0
                    Message.Text = "Product 1 was clicked"
                Case 1
                    Message.Text = "Product 2 was clicked"
                Case 2
                    Message.Text = "Product 3 was clicked"
                Case 3
                    Message.Text = "Product 4 was clicked"
                Case Else
                    Throw New Exception("You must click a valid list item.")
            End Select

        End Sub

    </script>
    
</head>
<body>

    <h3>BulletedList Class Data Binding Example</h3>

    <form id="form1" runat="server">
            
        <p>Click on an item in the list.</p>            
        <p>
        <asp:BulletedList id="ProductsBulletedList" 
            BulletStyle="Disc"
        DisplayMode="LinkButton" 
        DataTextField="ProductName"
        DataSourceID="SqlDataSource1"
        OnClick="ProductsBulletedList_Click"
        runat="server">                    
    </asp:BulletedList></p>
        
    <p>
    <asp:SqlDataSource id="SqlDataSource1"          
            ConnectionString="<%$ ConnectionStrings:NorthWindConnection%>"
            runat="server"
            SelectCommand="SELECT * FROM [Products] Where ProductID < 5">
        </asp:SqlDataSource></p>
        
    <p>        
    <asp:Label id="Message" 
        Font-Size="12"
        Width="168px" 
        Font-Bold="True" 
        runat="server"/></p>              
              
   </form>

</body>
</html>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft