How to: Respond to User Clicks in BulletedList Web Server Controls
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

How to: Respond to User Clicks in BulletedList Web Server Controls

You can configure a BulletedList control to display buttons for the control's items. When users click a button, the control posts the page back to the server and gives you an opportunity to run code in response to the user's click.

To respond to a user click in a BulletedList Web server control

  1. Create an event handler for the BulletedList control's Click event.

  2. In the event handler, get the Index property of the BulletedListEventArgs value passed to the handler.

  3. Using the index, get the appropriate item from the control and get the item's Text and Value properties.

Example

The following code example shows a page containing a BulletedList control that displays static items. The handler for the control's Click event displays which list item the user clicked.

<%@ Page Language="C#" %>
<script runat="server">
    protected void BulletedList1_Click(object sender, 
        BulletedListEventArgs e)
    {
        ListItem li = BulletedList1.Items[e.Index];
        Label1.Text = "You selected = " + li.Text + ", with value = " 
            + li.Value;
    }
</script>

<html>
<head id="Head1" runat="server">
</head>
<body>
    <form id="form1" runat="server">
        <asp:BulletedList ID="BulletedList1" 
            runat="server" 
            DisplayMode="LinkButton" 
            OnClick="BulletedList1_Click">
            <asp:ListItem Value="A">Item 1</asp:ListItem>
            <asp:ListItem Value="B">Item 2</asp:ListItem>
            <asp:ListItem Value="C">Item 3</asp:ListItem>
        </asp:BulletedList>
        <br />
        <asp:Label ID="Label1" runat="server" text="" />
    </form>
</body>
</html>

See Also

Show:
© 2016 Microsoft