Drop Down list with checkbox using java script and css in asp.net c#

In this article, we will get the drop down list with check box in asp.net C#, we have use this code for multiply choose  in a single drop  down list .
Design:-





Source code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dropdownlistwithcheckbox.aspx.cs"
    Inherits="Dropdownlistwithcheckbox" %>

<!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 id="Head1" runat="server">
    <title>Drop down list with Checkbox</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"
        rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
    <link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"
        rel="stylesheet" type="text/css" />
    <script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('[id*=listcource]').multiselect({
                includeSelectAllOption: true
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ListBox ID="listcource" runat="server" SelectionMode="Multiple">
        <asp:ListItem Text="MBA" Value="1" />
        <asp:ListItem Text="MCA" Value="2" />
        <asp:ListItem Text="M.Sc" Value="3" />
        <asp:ListItem Text="M.Com" Value="4" />
        <asp:ListItem Text="M.Tech" Value="5" />
    </asp:ListBox>
    <br />
    <br />
    <asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Submit" />
    </form>
</body>
</html>
  
Code behind (c#):-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Dropdownlistwithcheckbox : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Submit(object sender, EventArgs e)
    {
        string msg = "";
        foreach (ListItem item in listcource.Items)
        {
            if (item.Selected)
            {
                msg += item.Text + " " + item.Value + "\\n";
            }
        }
        ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + msg + "');", true);
    }

}


 Out-Put:-

Drop Down list with checkbox using java script and css in asp.net c# Drop Down list with checkbox using java script and css in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 1:58:00 PM Rating: 5

No comments:

Powered by Blogger.