
Navigator : Home > Tutorials > Controls Tutorials > ...
Working with BulletedList control in ASP.NET 2.0 and C#
This tutorial will show you how to use the control of BulletedList to show data in ASP.NET 2.0 and C#. 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
| using System.Web.UI.WebControls; |
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
We will use BulletedList1_Click event to show the selectedindex and selectedvalue.
protected void BulletedList1_Click(object sender, BulletedListEventArgs e) {
Label1.Text = "SelectedIndex=" + e.Index.ToString() + ",Value=" + BulletedList1.Items[e.Index].Value; } |
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.
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) { } protected void BulletedList1_Click(object sender, BulletedListEventArgs e) {
Label1.Text = "SelectedIndex=" + e.Index.ToString() + ",Value=" + BulletedList1.Items[e.Index].Value; } } |
We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!
Looking for the VB.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!