Asp.Net Drop down list multiple item selection by using Asp.Net Listbox

 

By using Asp.Net drop down list, we can select only one item at a time. To select multiple items from the drop down list, we have to use Asp.Net Listbox.

 

In this article how to select multiple items from the Listbox. For example we have the ArrayList which supplies as data source for Listbox as shown below. Binding the data source to the Listbox is same as binding the data source to the asp.net drop down list.

 

<%@ 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>Untitled Page</title>

 

</head>

 

<body>

 

    <form id="form1" runat="server">

 

    <div>

 

        <asp:ListBox ID="listbox1" runat="server" Height="100px" SelectionMode="Multiple"></asp:ListBox>

 

    </div>

 

    </form>

 

</body>

 

</html>

 

using System; 

using System.Collections; 

 

public partial class _Default : System.Web.UI.Page  

{ 

    protected void Page_Load(object sender, EventArgs e) 

    {

 

        ArrayList arrList = new ArrayList();

 

        arrList.Add("A0"); 

        arrList.Add("A1");

 

        arrList.Add("A2");

 

        arrList.Add("A3");

 

        arrList.Add("A4");

 

        arrList.Add("A5");

 

        listbox1.DataSource = arrList;

 

        listbox1.DataBind();

 

    }

 

}

 

As shown above, we can enable multiple item selection by assigning the value as Multiple to Listbox property SelectionMode.

You can select the multiple values from Listbox by holding the Ctrl key in the keyword as shown below. 

ListboxExp.zip (2.88 kb)