How to add an item to ListBox programmatically in asp.net c#

Add an item (ListItem) to ListBox
The following ASP.NET C# example code demonstrates to us how can we add an item to ListBox control programmatically at run time. ListBox is an ASP.NET list web server control. ListBox contains items collection. Each item of ListBox control represents a ListItem object. We can add ListItem object to ListBox control's items collection both statically and programmatically.

To add an item to ListBox control programmatically, we can call the Collection Class’s Add() method. This Add() method allows us to add an item to a collection. So we can easily add an item to the ListBox control as the Items Add(ListItem) method. Because ListBox contains an items collection that supports the addition of new items.

To Add an item (ListItem) to a ListBox control, first, we need to create the ListItem object. Each ListItem object has a Text property and optionally a Value property. We can also set the specified ListItem object Selected property value to true. After creating a ListItem object, we can add it to the ListBox control by calling Add() method.
ListBoxAddListItem.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e) {
        ListBox1.Items.Add(new ListItem(TextBox1.Text));
        Response.Write("Item Added: " + TextBox1.Text);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ListBox example: how to add ListItem dynamically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Controls" AssociatedControlID="ListBox1"></asp:Label>
        <asp:ListBox ID="ListBox1" runat="server">
            <asp:ListItem>Calendar</asp:ListItem>
            <asp:ListItem>Panel</asp:ListItem>
            <asp:ListItem>BulletedList</asp:ListItem>
            <asp:ListItem>AdRotator</asp:ListItem>
            <asp:ListItem>DropDownList</asp:ListItem>
            <asp:ListItem>ListBox</asp:ListItem>
            <asp:ListItem>Button</asp:ListItem>
        </asp:ListBox>
        <hr />
        <asp:Label ID="Label2" runat="server" Text="Input Item Text" AssociatedControlID="TextBox1"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Text="*"></asp:RequiredFieldValidator>
        <asp:Button ID="Button1" runat="server" Text="Add Item" OnClick="Button1_Click" />
    </div>
    </form>
</body>
</html>