ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.[Solved] Bootstrap MultiSelect DropDownList from Database not displaying CheckBoxes<p>Hi <a class="username" rel="smile">smile</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">Database</span></strong></p> <p>For this example I have used below database table with the following schema and data.</p> <pre class="brush: sql">CREATE TABLE [dbo].[Fruits]( [FruitId] [int] NOT NULL, [FruitName] [varchar](30) NOT NULL, CONSTRAINT [PK_Fruits_1] PRIMARY KEY CLUSTERED ( [FruitId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO INSERT [dbo].[Fruits] ([FruitId], [FruitName]) VALUES (1, N&#39;Mango&#39;) GO INSERT [dbo].[Fruits] ([FruitId], [FruitName]) VALUES (2, N&#39;Orange&#39;) GO INSERT [dbo].[Fruits] ([FruitId], [FruitName]) VALUES (3, N&#39;Banana&#39;) GO INSERT [dbo].[Fruits] ([FruitId], [FruitName]) VALUES (4, N&#39;Apple&#39;) GO INSERT [dbo].[Fruits] ([FruitId], [FruitName]) VALUES (5, N&#39;Papaya&#39;) GO</pre> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <p><strong>MasterPage.master</strong></p> <pre class="brush: html">&lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &nbsp;&nbsp;&nbsp; &lt;title&gt;&lt;/title&gt; &nbsp;&nbsp;&nbsp; &lt;asp:ContentPlaceHolder ID="head" runat="server"&gt; &nbsp;&nbsp;&nbsp; &lt;/asp:ContentPlaceHolder&gt; &lt;/head&gt; &lt;body&gt; &nbsp;&nbsp;&nbsp; &lt;form id="form1" runat="server"&gt; &nbsp;&nbsp;&nbsp; &lt;div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:ContentPlaceHolder&gt; &nbsp;&nbsp;&nbsp; &lt;/div&gt; &nbsp;&nbsp;&nbsp; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong>CS.aspx</strong></p> <pre class="brush: html">&lt;%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" &nbsp;&nbsp;&nbsp; CodeFile="CS.aspx.cs" Inherits="CS" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"&gt; &nbsp;&nbsp;&nbsp; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt; &nbsp;&nbsp;&nbsp; &lt;link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rel="stylesheet" type="text/css" /&gt; &nbsp;&nbsp;&nbsp; &lt;script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"&gt;&lt;/script&gt; &nbsp;&nbsp;&nbsp; &lt;link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rel="stylesheet" type="text/css" /&gt; &nbsp;&nbsp;&nbsp; &lt;script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type="text/javascript"&gt;&lt;/script&gt; &nbsp;&nbsp;&nbsp; &lt;script type="text/javascript"&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(function () { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $('[id*=lstHead]').multiselect({ includeSelectAllOption: true }); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }); &nbsp;&nbsp;&nbsp; &lt;/script&gt; &nbsp;&nbsp;&nbsp; &lt;div class="col-md-3"&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;label class="control-label" style="margin-top: 10px;"&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Head&lt;/label&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:ListBox ID="lstHead" runat="server" SelectionMode="Multiple" AutoPostBack="true" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OnSelectedIndexChanged="lstHead_SelectedIndexChanged" class="form-control"&gt;&lt;/asp:ListBox&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Button Text="Submit" OnClick="Submit" runat="server" CssClass="btn btn-default" /&gt; &nbsp;&nbsp;&nbsp; &lt;/div&gt; &lt;/asp:Content&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong> </p> <p><strong>C#</strong> </p> <pre class="brush: csharp">using System.Configuration; using System.Data; using System.Data.SqlClient;</pre> <p><strong>VB.Net</strong> </p> <pre class="brush: vb">Imports System.Data Imports System.Data.SqlClient</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>CS.aspx.cs</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { lstHead.DataSource = GetData(&#34;SELECT FruitId,FruitName FROM Fruits&#34;); lstHead.DataTextField = &#34;FruitName&#34;; lstHead.DataValueField = &#34;FruitId&#34;; lstHead.DataBind(); } } protected void Submit(object sender, EventArgs e) { string message = &#34;&#34;; foreach (ListItem item in lstHead.Items) { if (item.Selected) { message += item.Text + &#34; &#34; + item.Value + &#34;\\n&#34;; } } ClientScript.RegisterClientScriptBlock(this.GetType(), &#34;alert&#34;, &#34;alert(&#39;&#34; + message + &#34;&#39;);&#34;, true); } protected void lstHead_SelectedIndexChanged(object sender, EventArgs e) { } private DataSet GetData(string query) { string conString = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; SqlCommand cmd = new SqlCommand(query); using (SqlConnection con = new SqlConnection(conString)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; using (DataSet ds = new DataSet()) { sda.Fill(ds); return ds; } } } }</pre> <p><strong>VB.aspx.vb</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not IsPostBack Then lstHead.DataSource = GetData(&#34;SELECT FruitId,FruitName FROM Fruits&#34;) lstHead.DataTextField = &#34;FruitName&#34; lstHead.DataValueField = &#34;FruitId&#34; lstHead.DataBind() End If End Sub Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs) Dim message As String = &#34;&#34; For Each item As ListItem In lstHead.Items If item.Selected Then message += item.Text &amp; &#34; &#34; + item.Value &amp; &#34;\n&#34; End If Next ClientScript.RegisterClientScriptBlock(Me.[GetType](), &#34;alert&#34;, &#34;alert(&#39;&#34; &amp; message &amp; &#34;&#39;);&#34;, True) End Sub Protected Sub lstHead_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) End Sub Private Function GetData(ByVal query As String) As DataSet Dim conString As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Dim cmd As SqlCommand = New SqlCommand(query) Using con As SqlConnection = New SqlConnection(conString) Using sda As SqlDataAdapter = New SqlDataAdapter() cmd.Connection = con sda.SelectCommand = cmd Using ds As DataSet = New DataSet() sda.Fill(ds) Return ds End Using End Using End Using End Function</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/Gk0b5x4.gif" alt="" width="338" height="244" /></p>https://www.aspforums.net:443/Threads/212040/Solved-Bootstrap-MultiSelect-DropDownList-from-Database-not-displaying-CheckBoxes/https://www.aspforums.net:443/Threads/212040/Solved-Bootstrap-MultiSelect-DropDownList-from-Database-not-displaying-CheckBoxes/Wed, 03 Jan 2018 02:24:40 GMT