Please refer this code
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" Text='<%# Eval("Country") %>' AutoPostBack="true" OnCheckedChanged="CheckBox1_OnCheckedChanged" runat="server" />
</ItemTemplate>
</asp:DataList>
<asp:DataList ID="DataList2" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>
Contact Name
</th>
<th>
Company Name
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblContactName" Text='<%# Eval("ContactName") %>' runat="server" />
</td>
<td>
<asp:Label ID="lblCompanyName" Text='<%# Eval("CompanyName") %>' runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Namespace
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
PopulateDataList();
}
}
private void PopulateDataList()
{
string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Distinct(Country) From Customers", conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
}
}
}
}
protected void CheckBox1_OnCheckedChanged(object sender, EventArgs e)
{
CheckBox chk = sender as CheckBox;
string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT ContactName , CompanyName From Customers Where Country = @Country", conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
cmd.Parameters.AddWithValue("@Country", chk.Text);
DataSet ds = new DataSet();
da.Fill(ds);
DataList2.DataSource = ds;
DataList2.DataBind();
}
}
}
}