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






<%@ 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