Friday, March 14, 2014

Asp.NET : Add ListItem to BulletedList

Default.aspx :-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form runat="server" id="form" >

    <h1 style="border-style: dashed; border-color: #008000; font-family: Valken; color: #000080">BulletedList</h1>

    <asp:BulletedList runat="server" ID="bl1">
        <asp:ListItem>Mahi</asp:ListItem>
        <asp:ListItem>Appy</asp:ListItem>
        <asp:ListItem>Ruzin</asp:ListItem>
    </asp:BulletedList>

    </form>
</body>
</html>

Default.aspx.cs :-


public partial class _Default : System.Web.UI.Page
{
    const int count = 10;

    string GetDisplayItem(int n)
    {
        return n.ToString();
    }

    protected override void OnLoad(EventArgs e)
    {
        bl1.Items.Clear();

        for (int i = 1; i <= count; i++)
            bl1.Items.Add(new ListItem(GetDisplayItem(i)));

        base.OnLoad(e);
    }
}

Output:-


No comments:

Post a Comment