Hi kankon,
Check this sample. now take its reference.
HTML
<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">
$(document).ready(function () {
$('#ddlCountries').multiselect({
checkboxName: function (option) {
var $optgroup = $(option).closest('optgroup');
if ($optgroup.id == 'checkboxName-1') {
return 'group1[]';
}
else {
return 'group2[]';
}
}
});
});
</script>
<div class="form-group">
<label class="col-sm-2 control-label">
Multiselect</label>
<div class="col-sm-10">
<select id="ddlCountries" name="multiselect[]" multiple="multiple" required>
<optgroup label="كهرباء" id="checkboxName-1">
<option value="Argentina">مهندس كهرباء</option>
<option value="Austria">اشرافي/ مساعد مهندس كهرباء</option>
<option value="Belgium">فني كهرباء</option>
</optgroup>
<optgroup label="مدني" id="checkboxName-2">
<option value="Brazil">مهندس مدني</option>
<option value="Canada">اشرافي/ مساعد مهندس مدني</option>
<option value="Denmark">فني مدني</option>
</optgroup>
<optgroup label="ميكاكنيك" id="checkboxName-3">
<option value="Finland">مهندس ميكانيك</option>
<option value="France">اشرافي/ مساعد مهندس ميكانيك</option>
<option value="Germany">فني ميكاكنيك</option>
</optgroup>
<optgroup label="زراعة / نظافة / خدمات فندقية" id="checkboxName-4">
<option value="Ireland">مهندس زراعة / نظافة / خدمات فندقية</option>
<option value="Italy">اشرافي/ مساعد مهندس زراعة / نظافة / خدمات فندقية</option>
<option value="Mexico">فني زراعة / نظافة / خدمات فندقية</option>
</optgroup>
<optgroup label="حاسوب / الكترونيات / اتصالات" id="checkboxName-5">
<option value="Norway">مهندس حاسوب / الكترونيات / اتصالات</option>
<option value="Poland">اشرافي/ مساعد مهندس حاسوب / الكترونيات / اتصالات</option>
<option value="Portugal">فني حاسوب / الكترونيات / اتصالات</option>
</optgroup>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="OnSubmit" />
</div>
</div>
<br />
<rsweb:ReportViewer ID="ReportViewer1" runat="server">
</rsweb:ReportViewer>
<hr />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
private void BindReport(string query)
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
Customers dsCustomers = GetData(query);
ReportDataSource datasource = new ReportDataSource("DataSet1", dsCustomers.Tables["Customers"]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
protected void OnSubmit(object sender, EventArgs e)
{
string query = "SELECT CustomerID,ContactName,City,Country FROM Customers";
string condition = string.Empty;
foreach (string item in Request.Form["multiselect[]"].Split(','))
{
condition += string.Format("'{0}',", item);
}
if (!string.IsNullOrEmpty(condition))
{
condition = string.Format(" WHERE Country IN ({0})", condition.Substring(0, condition.Length - 1));
}
this.BindReport(query + condition);
}
private Customers GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["NORTHWINDConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (Customers dsCustomers = new Customers())
{
sda.Fill(dsCustomers, "Customers");
return dsCustomers;
}
}
}
}
}
VB.Net
Private Sub BindReport(ByVal query As String)
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc")
Dim dsCustomers As Customers = GetData(query)
Dim datasource As ReportDataSource = New ReportDataSource("DataSet1", dsCustomers.Tables("Customers"))
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(datasource)
End Sub
Protected Sub OnSubmit(ByVal sender As Object, ByVal e As EventArgs)
Dim query As String = "SELECT CustomerID,ContactName,City,Country FROM Customers"
Dim condition As String = String.Empty
For Each item As String In Request.Form("multiselect[]").Split(","c)
condition += String.Format("'{0}',", item)
Next
If Not String.IsNullOrEmpty(condition) Then
condition = String.Format(" WHERE Country IN ({0})", condition.Substring(0, condition.Length - 1))
End If
Me.BindReport(query & condition)
End Sub
Private Function GetData(ByVal query As String) As Customers
Dim conString As String = ConfigurationManager.ConnectionStrings("NORTHWINDConnectionString").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand(query, con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dsCustomers As Customers = New Customers()
sda.Fill(dsCustomers, "Customers")
Return dsCustomers
End Using
End Using
End Using
End Using
End Function
Screenshot