How to set default selected items in a ListBox in listbox set selected items
ListBox is an web server control. we can select a single item or multiple items at a item from listbox control. in this example, we will see that how can we select multiple random items from listbox control programmatically at run time.

to select listbox multiple items programmatically we need to apply few techniques. first we apply a linq query to find specific items from listbox items collection depends on developer's criteria. the linq query return a items collection from listbox which items we want to select programmatically. next we loop through the newly created items collection and set each item Selected property value to true. finally we get specified items are programmatically selected in listbox control.

the following c# example code demonstrate us how can we select listbox multiple items programmatically in an application.

<%@ Page Language="C#" AutoEventWireup="true"%>    
<!DOCTYPE html>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
            string[] birds = { 
                                 "Rufous Scrubbird",
                                 "Golden Bowerbird",
                                 "Great Bowerbird",
                                 "Andean Goose",
                                 "Spotted Bowerbird"

            ListBox1.DataSource = birds;

            ListBox1.Rows = ListBox1.Items.Count;
            //find specific items from listbox
            var items = from ListItem li in ListBox1.Items
                        where li.Text.Contains("Bowerbird")
                        select li;
            //programmatically select specific items 
            //by default first time those items are selected.
            foreach(ListItem li in items)
                li.Selected = true;
<html xmlns="">        
<head id="Head1" runat="server">        
    <title> listbox set selected items</title>  
    <form id="form1" runat="server">        
        <h2 style="color:MidnightBlue; font-style:italic;">        
   example - set selected items
        <hr width="550" align="left" color="Gainsboro" />        
            Text="select item(s) from listbox."
        <br /><br />  
            Font-Names="Comic Sans MS"
More examples