DotNet Tutorials

Server Intellect

 Working with BulletedList control in ASP.NET 2.0 and VB

This tutorial will show you how to use the control of BulletedList to show data in ASP.NET and VB.NET 2.0. BulletedList class can create a control that generates a list of items in a bulleted format. First, import the namespace of System.Web.UI.WebControls
Imports System.Web.UI.WebControls

We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!

We will use BulletedList1_Click event to show the selectedindex and selectedvalue.

Protected Sub BulletedList1_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.BulletedListEventArgs) Handles BulletedList1.Click
Label1.Text = "SelectedIndex=" + e.Index.ToString() & ",Value=" & BulletedList1.Items(e.Index).Value
End Sub

The front end Default.aspx page looks something like this:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>BulletedList Demo</title>
<link id="InstanceStyle" href="StyleSheet.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
<fieldset style="width: 400px">
<legend class="mainTitle">BulletedList Example</legend>
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="true"></asp:Label>
<hr />
<table border="0" width="100%">
<tr align="center" style="text-decoration: underline;">
<td>
NotSet/Disc</td>
<td>
Numbered</td>
<td>
LowerAlpha</td>
</tr>
<tr>
<td>
<asp:BulletedList ID="BulletedList1" runat="server" AppendDataBoundItems="true" DataSourceID="AccessDataSource1"
DataTextField="PlaceTitle" DataValueField="RegionCode" DisplayMode="LinkButton"
OnClick="BulletedList1_Click">
<asp:ListItem Value="020">guangzhou</asp:ListItem>
<asp:ListItem Value="025">nanjing</asp:ListItem>
</asp:BulletedList>
</td>
<td>
<asp:BulletedList ID="BulletedList2" runat="server" AppendDataBoundItems="true" DataSourceID="AccessDataSource1"
DataTextField="PlaceTitle" DataValueField="RegionCode" DisplayMode="Text" BulletStyle="Numbered">
<asp:ListItem Value="020">guangzhou</asp:ListItem>
<asp:ListItem Value="025">nanjing</asp:ListItem>
</asp:BulletedList>
</td>
<td>
<asp:BulletedList ID="BulletedList3" runat="server" AppendDataBoundItems="true" DataSourceID="AccessDataSource1"
DataTextField="PlaceTitle" DataValueField="RegionCode" DisplayMode="Text"
BulletStyle="LowerAlpha">
<asp:ListItem Value="020">guangzhou</asp:ListItem>
<asp:ListItem Value="025">nanjing</asp:ListItem>
</asp:BulletedList>
</td>
</tr>
</table>
</fieldset>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/CityData.mdb"
SelectCommand="SELECT PlaceTitle,RegionCode FROM [SupperCity]"></asp:AccessDataSource>
</div>
</form>
</body>
</html>

The flow for the code behind page is as follows.

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub BulletedList1_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.BulletedListEventArgs) Handles BulletedList1.Click
Label1.Text = "SelectedIndex=" + e.Index.ToString() & ",Value=" & BulletedList1.Items(e.Index).Value
End Sub
End Class

Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!



Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect