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; |
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
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;
} |
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
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>
|
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
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;
}
}
|
Download the Full Working Version of this Project written with Visual Studio.NET C# 2005 Here!
Looking for the VB.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!