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

.NET Framework 3.0

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.


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;

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

See Also