Beginners Guide to the BulletedList

The BulletedList is an ASP.net server control which is new, with v2.0 of ASP.Net. At first glance, you might think that, being a way to use a database to populate an HTML select list is a really nice feature. However, if that’s all there was too it, you’d be correct, but the feature list is really nice!

First off, let’s start with the data binding features. Naturally, as you’d expect with a v2.0 control, the DataSourceID can be used to populate the list, along with DataTextField and DataValueField properties for populating the Text and Values of each list item.

Now, let’s couple that with the DisplayMode property. There are three modes:

  • HyperLink
  • LinkButton
  • Text (default)

First, let’s look at the Hyperlink mode. It can be used with either Databound or non-DataBound BulletedLists. When using a Databound BulletedList, the DataValueField can be populated with the actual URL, while any text field can be used for populating the DataTextField. If the BulletedList is non-DataBound, the actual URL can be added to the ‘Value’ attribute of each ListItem.

Also, the Linkbutton mode can be used to fire off a subroutine or function to do just about anything within the confines of ASP.net. Using code, or another DataSourceID, by choosing an item in the BulletedList to trigger that code. For instance, the display text of each item can be used in a SQL statement’s ‘Where’ clause, or any other use which uses the text or value of the selected list item. In the BulletedList tag, the OnClick event is used:

<asp:BulletedList ID="BL1" Runat="Server" OnClick="Choose_Item" />

Then, the actual code is placed in a subroutine, somewhat like this:

Sub Choose_Item (Src As Object, e As BulletedListEventArgs) dim MySQL as String="Select (FieldList) from (TableName) where (FieldName)='" & _ BL1.Items(e.Index) & "'" ' Rest of code or DataSource SelectCommand assignment goes here End Sub

There are 8 different style which can be used with the BulletedStyle property, which are, for the most part, fairly self-explanatory:

  • Circle – Hollow Circle
  • Disc – most common Bullet
  • LowerAlpha – Letters
  • LowerRoman – Roman Numerals
  • Numbered
  • Square
  • UpperAlpha – Letters
  • UpperRoman – Roman Numerals
  • CustomImage

Naturally, along with that, all the normal Server Control properties are available, Backcolor, Forecolor, Borderstyles, Fontstyles, etc. If you notice, the last item in the list is ‘CustomImage’. When this style is chosen, along with the ‘BulletImageURL’ property assignment, a custom bullet image can be used instead of using one of the default styles. Here’s an example:

  • Item 1
  • Item 2
  • Item 3
<asp:BulletedList ID="blexample" Runat="Server" BulletImageUrl="/images/bluearrow.gif" BulletStyle="CustomImage"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> </asp:BulletedList>

As you can easily see, Bulletedlists can be very useful in your every day ASP.Net coding life. It kind of makes you wonder “Why wasn’t this included before?

Related Posts:

  • No Related Posts
Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!