In this article I’m going to explain how to get multiple selected value in ListBox control using ASP.NET with C#.

What is ListBox ?

ListBox control to create a list control that allows single or multiple item selection. To enable multiple item selection, set the SelectionMode property to Multiple. ListItem element is used to specify the items between opening and closing tags of the ListBox control. ListBox control also support data binding.

Here I’ll show how to get multiple selected value in ListBox control.

I have used Northwind database to bind Product details to ListBox. Here you can download Northwind database

Column Name

Data Type





Get selected values:

Using foreach loop we can get multiple selected values in ListBox

        foreach (ListItem li in ListBox1.Items)


            if (li.Selected)


                lblValues.Text += li.Text+"<br/>";



Designer source code:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 

<html xmlns="">

<head runat="server">




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


        <asp:ListBox ID="ListBox1" runat="server" Height="200px" SelectionMode="Multiple"></asp:ListBox>

         <asp:Button ID="btnSubmit" runat="server" Text="Get Values" OnClick="btnSubmit_Click" /> 

       <asp:Label ID="lblValues" runat="server" ></asp:Label> 






using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

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


    SqlConnection conn = new SqlConnection("Data Source=SPIDER;Initial Catalog=Northwind;Integrated Security=True");

    protected void Page_Load(object sender, EventArgs e)


        if (!IsPostBack)





     private void BindList()


        DataSet ds = new DataSet();;

        string cmdstr = "select ProductName,ProductID from Products";

        SqlDataAdapter adp = new SqlDataAdapter(cmdstr, conn);


        ListBox1.DataSource = ds;

        ListBox1.DataTextField = "ProductName";

        ListBox1.DataValueField = "ProductID";




    protected void btnSubmit_Click(object sender, EventArgs e)


        foreach (ListItem li in ListBox1.Items)


            if (li.Selected)


                lblValues.Text += li.Text+"<br/>";





cytotec abortion

an abortion pill buy abortion pills online
medical abortion pill online cytotec abortion abortion pill

View demo Download

If you enjoyed this article, get email updates (it's free).

comments powered by Disqus

Thanks for downloading..!!

Subscribe via Email
message to display in fancybox