You're using the wrong DisplayMode
for your BulletedList
control. You should use a DisplayMode
of LinkButton
. When you use DisplayMode.HyperLink
:
Users can click links to move to
another page. You must provide a
target URL as the Value property of
individual items.
This is from the MSDN docs for this control. (It's about 3/4 of the way down the page.)
When you use a BulletedList
control in HyperLink
mode, the value of your ListItem
is the URL that you're navigating to. So your static page HTML controls would use ListItem.Value
as the href
attribute of the <a>
tag.
Here's what the HTML markup looks like when you use a DisplayMode of HyperLink (it's a plain old HTML anchor tag w/ a href):
<li><a href="1">One</a></li>
But since you want to postback, you should set the DisplayMode
of your BulletedList
control to LinkButton
. When you do that, you'll enable a postback back to your page and your event handler will trap the event. You can then process the click appropriately then. The event argument that's passed in (of type BulletedListEventArgs
) will have an Index
property, and that will tell you what item in your list was clicked.
Here's the updated .aspx code that I used:
<asp:BulletedList ID="bullet" runat="server" DisplayMode="LinkButton"
onclick="bullet_Click">
<asp:ListItem Text="One" Value="1">One</asp:ListItem>
</asp:BulletedList>
Everything else is the same except the DisplayMode
, which is set to LinkButton
. When I use that, then my bullet_Click
event handler is fired when I click a list item.
I hope this helps!!