asp.net - How to data bind a BulletedList with an array

DataBind a BulletedList with array
The following asp.net c# example code demonstrate us how can we data bind a BulletedList control with Array data source. BulletedList is an asp.net list web server control. BulletedList control can be empty or can have one or more items as ListItem object. We can data bind a BulletedList with an Array object for dynamically generate ListItem objects in BulledtedList from Array elements.

To populate a BulletedList from Array data source, first we need to initialize an Array object. In this tutorial we initializes a String Array. Then we need to add items/elements to Array object. Next, we define the BulletedList control's data source is newly created Array object by BulletedList DataSource property. Finally, we call the BulletedList DataBind() method to generate items in BulledtedList from Array data source.
StringArrayBulletedList.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    protected void Button1_Click(object sender, System.EventArgs e)
    {
        string[] controlArray = { "AdRotator", "Label", "CheckBox", "MultiView", "Calendar" };
        Label1.Text = "String array created and bind with BulletedList successfully!";
        BulletedList1.DataSource = controlArray;
        BulletedList1.DataBind();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to populate (DataBind) BulletedList using string array DataSource in asp.net</title>
</head> 
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">asp.net array example:<br />String Array and BulletedList</h2>
        <asp:Label 
             ID="Label1" 
             runat="server" 
             Font-Size="Large"
             ForeColor="MediumPurple"
             Font-Bold="true"
             Font-Italic="true"
             >
        </asp:Label>
        <br /><br />
        <asp:BulletedList 
             ID="BulletedList1" 
             runat="server" 
             BackColor="Crimson" 
             ForeColor="FloralWhite" 
             BorderWidth="2"
             BorderColor="Red"
             BulletStyle="Circle"
             Width="250"
             >
        </asp:BulletedList>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             OnClick="Button1_Click"
             Font-Bold="true"
             Text="Populate BulletedList With String Array"
             ForeColor="Crimson"
             />   
    </div>
    </form>
</body>
</html>
More asp.net examples