Hi ashraft1,
Refer below sample and also refer below link. I have take reference to below link and created below sample.
SQL
CREATE PROCEDURE FilterGetCustomers
@Country VARCHAR(MAX) = NULL
AS
BEGIN
SELECT
CustomerId,
Name,
Country
FROM Customers
WHERE Country IN(
SELECT Item FROM dbo.SplitString(@Country, ',')
) OR @Country IS NULL
END
HTML
<asp:CheckBoxList ID="chkCountry" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Search">
<asp:ListItem Text="United States" Value="United States"></asp:ListItem>
<asp:ListItem Text="India" Value="India"></asp:ListItem>
<asp:ListItem Text="France" Value="France"></asp:ListItem>
<asp:ListItem Text="Russia" Value="Russia"></asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:Repeater ID="rptCustomers" runat="server">
<HeaderTemplate>
<table>
<tr>
<th>
CustomerId
</th>
<th>
Name
</th>
<th>
Country
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblCustomerId" runat="server" Text='<%# Eval("CustomerId") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>'></asp:Label>
</td>
</tr>
<br />
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Namespaces
C#
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
VB.Net
Imports System.Data.SqlClient
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid("");
}
}
private void BindGrid(string country)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("FilterGetCustomers", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
if (!string.IsNullOrEmpty(country))
{
cmd.Parameters.AddWithValue("@Country", country);
}
using (SqlDataAdapter sda = new SqlDataAdapter())
{
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
rptCustomers.DataSource = dt;
rptCustomers.DataBind();
}
}
}
}
protected void Search(object sender, EventArgs e)
{
string condition = string.Empty;
foreach (ListItem item in chkCountry.Items)
{
condition += item.Selected ? string.Format("{0},", item.Value) : "";
}
BindGrid(condition);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
BindGrid("")
End If
End Sub
Private Sub BindGrid(ByVal country As String)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("FilterGetCustomers", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
If Not String.IsNullOrEmpty(country) Then
cmd.Parameters.AddWithValue("@Country", country)
End If
Using sda As SqlDataAdapter = New SqlDataAdapter()
sda.SelectCommand = cmd
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
rptCustomers.DataSource = dt
rptCustomers.DataBind()
End Using
End Using
End Using
End Sub
Protected Sub Search(ByVal sender As Object, ByVal e As EventArgs)
Dim condition As String = String.Empty
For Each item As ListItem In chkCountry.Items
condition += If(item.Selected, String.Format("{0},", item.Value), "")
Next
BindGrid(condition)
End Sub
Screenshot
