Add ListItem to BulletedList : BulletedList « ASP.net Controls « ASP.NET Tutorial

Home
ASP.NET Tutorial
1.ASP.Net Instroduction
2.Language Basics
3.ASP.net Controls
4.HTML Controls
5.Page Lifecycle
6.Response
7.Collections
8.Validation
9.Development
10.File Directory
11.Sessions
12.Cookie
13.Cache
14.Custom Controls
15.Profile
16.Configuration
17.LINQ
18.ADO.net Database
19.Data Binding
20.Ajax
21.Authentication Authorization
22.I18N
23.Mobile
24.WebPart
25.XML
ASP.NET Tutorial » ASP.net Controls » BulletedList 
3.6.3.Add ListItem to BulletedList
<%@ Page Language="C#" Debug="true" Trace="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
const int _itemCount = 10;
        
string GetDisplayItem(int n)
{
    return "Item #" + n.ToString();
}

protected override void OnLoad(EventArgs e)
{
    _displayList.Items.Clear();
    
    for (int i=0; i<_itemCount; i++)
        _displayList.Items.Add(new ListItem(GetDisplayItem(i)));
    
    _messageH2.InnerText = "Total number of items = " + _itemCount.ToString();
    
    base.OnLoad(e);
}    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Simple page with controls</title>
</head>
<body>
    <form runat="server" id="_form" >
    <h1>Test ASP.NET 2.0 Page with controls</h1>
    <asp:BulletedList runat="server" ID="_displayList">
        <asp:ListItem>Sample Item 1</asp:ListItem>
        <asp:ListItem>Sample Item 2</asp:ListItem>
        <asp:ListItem>Sample Item 3</asp:ListItem>
    </asp:BulletedList>

    <h2 runat="server" id="_messageH2">Total number of items = xx</h2>
    </form>
</body>
</html>
3.6.BulletedList
3.6.1.Fill all asp:BulletedList style constant to asp:BulletedList, and click action (C#)
3.6.2.Add value to asp:BulletedList in a for loop (VB.net)
3.6.3.Add ListItem to BulletedList
3.6.4.Dynamically populating a BulletedList server control
3.6.5.BulletedList with DynamicImage
3.6.6.DisplayMode of BulletedList
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.