<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>BulletedList Control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>BulletedList Control</h1>
<asp:BulletedList ID="bltList" runat="server"
OnClick="bltList_Click"
Target="_blank">
<asp:ListItem Value="http://www.java2java.com/">java2s.com</asp:ListItem>
<asp:ListItem Value="http://www.java2java.com">java2s.com</asp:ListItem>
<asp:ListItem Value="http://www.java2java.com" Text="java2s"></asp:ListItem>
</asp:BulletedList>
<table>
<tr>
<td colspan=3 id="tdMessage" runat="server">
</td>
</tr>
<tr>
<td>
<u>BulletStyle</u>
</td>
<td>
<u>FirstBulletNumber</u>
</td>
<td>
<u>DisplayMode</u>
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="lbBulletStyle" runat="server" AutoPostBack=true OnSelectedIndexChanged="lb_SelectedIndexChanged">
<asp:ListItem>NotSet</asp:ListItem>
<asp:ListItem>Numbered</asp:ListItem>
<asp:ListItem>LowerAlpha</asp:ListItem>
<asp:ListItem>UpperAlpha</asp:ListItem>
<asp:ListItem>LowerRoman</asp:ListItem>
<asp:ListItem>UpperRoman</asp:ListItem>
<asp:ListItem>Disc</asp:ListItem>
<asp:ListItem>Circle</asp:ListItem>
<asp:ListItem>Square</asp:ListItem>
<asp:ListItem>CustomImage</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:ListBox ID="lbFirstBulletNumber" runat="server"
AutoPostBack=true
Width=50
OnSelectedIndexChanged="lb_SelectedIndexChanged">
<asp:ListItem Selected="True">1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:ListBox ID="lbDisplayMode" runat="server" AutoPostBack=true OnSelectedIndexChanged="lb_SelectedIndexChanged">
<asp:ListItem>NotSet</asp:ListItem>
<asp:ListItem>Text</asp:ListItem>
<asp:ListItem>HyperLink</asp:ListItem>
<asp:ListItem>LinkButton</asp:ListItem>
</asp:ListBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
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 lb_SelectedIndexChanged(object sender, EventArgs e){
ListBox lb = (ListBox)sender;
string strID = lb.ID;
string strValue = lb.SelectedValue;
switch (strID){
case "lbBulletStyle": BulletStyle style = (BulletStyle)Enum.Parse(typeof(BulletStyle), strValue);
bltList.BulletStyle = style;
if (style == BulletStyle.CustomImage)
{
bltList.BulletImageUrl = "A.bmp";
}
break;
case "lbFirstBulletNumber":
bltList.FirstBulletNumber = Convert.ToInt32(strValue);
break;
case "lbDisplayMode":
BulletedListDisplayMode displayMode = (BulletedListDisplayMode)Enum.Parse(typeof(BulletedListDisplayMode), strValue);
bltList.DisplayMode = displayMode;
break;
default:
break;
}
}
protected void bltList_Click(object sender, BulletedListEventArgs e){
BulletedList b = (BulletedList)sender;
tdMessage.InnerHtml = "Selected index: " + e.Index.ToString() +
"<br>" +
"Selected value: " + b.Items[e.Index].Value +
"<br>";
}
}
|