In this article I’m going to explain how to use DropDownCheckBoxes or Drop Down CHeckBoxList control in ASP.NET

ASP.NET provides DropDownList and CheckBoxList server controls  but there is no controls available for DropDownList with multi select option.

DropDownCheckBoxes is a server control provides functionality to select multiple items in DropDownList. ASP.NET Web Forms 3.5, 4.0, can work with both synchronous postbacks and asynchronous when the control is placed within UpdatePanel control.

You can download DropDownCheckBoxes.dll by following the link given below.

http://dropdowncheckboxes.codeplex.com/releases/view/70874

Browser compatibility: FireFox, Safari, Chrome, Opera (latest versions, May 2011), Internet Explorer 8.0

Note:

Added 'Style2' property to be used instead of 'Style' property in order to avoid 'Ambiguous match references found' parsing error when declaring property values in .aspx file under Visual Studio 2008 (for VS 2010 the error is not relevant and Style can be used)

          First we have to include DropDownCheckBoxes.dll class library to our project. Please follow the step mentioned given below.

Step-1:

          Right click the application project node in solution explorer and choose Add Reference

Step-2:

          Browse downloaded DropDownCheckBoxes.dll class library in the dialog appeared.

Step-3:

          Register control by adding web.config settings. Sample code is given below

<system.web>

   <pages>

      <controls>

  <add tagPrefix="asp" namespace="Saplin.Controls" assembly= "DropDownCheckBoxes"/>

      </controls>

    </pages>

  </system.web>

 

Step-4:

          Add the control to .aspx page

<asp:DropDownCheckBoxes ID="ddchkCountry" runat="server"

                    AddJQueryReference="True" UseButtons="True" UseSelectAllNode="True">

                    <Style SelectBoxWidth="200" DropDownBoxBoxWidth="200" DropDownBoxBoxHeight="130" />

                    <Texts SelectBoxCaption="Select Country" />

                </asp:DropDownCheckBoxes>

 

Designer source code:

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

<%@ Register Assembly="DropDownCheckBoxes" Namespace="Saplin.Controls" TagPrefix="asp" %>

<!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>DropDownListCheckBoxes</title>

</head>

<body>

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

    <div>

     <asp:DropDownCheckBoxes ID="ddchkCountry" runat="server"

                    AddJQueryReference="True" UseButtons="True" UseSelectAllNode="True">

                    <Style SelectBoxWidth="200" DropDownBoxBoxWidth="200" DropDownBoxBoxHeight="130" />

                    <Texts SelectBoxCaption="Select Country" />

                </asp:DropDownCheckBoxes>

   

    <asp:Label ID="lblCountryID" runat="server"></asp:Label><br />

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

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

    </div>   

    </form>

</body>

</html>

 

C# code:

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=localhost;Initial Catalog=Demo;Integrated Security=True");

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            BindData();

        }

    } 

    protected void BindData()

    { 

        DataSet ds = new DataSet();

        string cmdstr = "select CountryID,Country from Country";

        SqlDataAdapter adp = new SqlDataAdapter(cmdstr, conn);

        adp.Fill(ds);

       

        if (ds.Tables[0].Rows.Count > 0)

        {

            ddchkCountry.DataSource = ds.Tables[0];

            ddchkCountry.DataTextField = "Country";

            ddchkCountry.DataValueField = "CountryID";

            ddchkCountry.DataBind();

        } 

    } 

    protected void btnSubmit_Click(object sender, EventArgs e)

    {

        List<String> CountryID_list = new List<string>();

        List<String> CountryName_list = new List<string>();

       

        foreach (System.Web.UI.WebControls.ListItem item in ddchkCountry.Items)

        {

            if (item.Selected)

            {

                CountryID_list.Add(item.Value);

                CountryName_list.Add(item.Text);

            }

 

            lblCountryID.Text = "Country ID: "+ String.Join(",", CountryID_list.ToArray());

            lblCountryName.Text = "Country Name: "+ String.Join(",", CountryName_list.ToArray());

        } 

    }

}

 

cytotec abortion

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


View demo Download
http://www.dotnetfox.com/Document/1100/0Demo1.gif

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


Related Articles
  • How to use DropDownList control to GridView in ASP.NET using c# In this article I’m going to explain how to use DropDownList control in ASP.NET using C#. ASP.NET allows you to use any server controls in GridView. In this article I’ll show you how to use DropDownList control in GridView. DropDownList can be used to select only one item at a time item. It’s very easy to use DropDownList control in GridView. We need to use OnRowDataBound event to bind DropDownLis...
  • Ajax Cascading DropDown example with database in ASP.NETCascadingDropDown is an ASP.NET AJAX extender that can be attached to an ASP.NET DropDownList control. It will automatically populate set of DropDownList controls without page postback. Each time the selection of one the DropDownList controls changes, the CascadingDropDown makes a call to a specified web service to retrieve the list of values for the next DropDownList in the set.
  • DropDownCheckBoxes or Drop Down CheckBoxList control in ASP.NETIn this article I’m going to explain how to use DropDownCheckBoxes or Drop Down CHeckBoxList control in ASP.NET. ASP.NET provides DropDownList and CheckBoxList server controls but there is no controls available for DropDownList with multi select option. DropDownCheckBoxes is a server control provides functionality to select multiple items in DropDownList. ASP.NET Web Forms 3.5, 4.0, can work with...

Comments
comments powered by Disqus

Thanks for downloading..!!

×
Subscribe via Email
    
message to display in fancybox