Hi sambath,
Please refer below sample.
HTML
<div>
<asp:CheckBox ID="chkPending" runat="server" Text="Pending" OnCheckedChanged="StatusChanged"
AutoPostBack="true" />
<asp:CheckBox ID="chkComplete" runat="server" Text="Complete" OnCheckedChanged="StatusChanged"
AutoPostBack="true" />
<br />
<br />
<asp:GridView ID="gvStatus" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="UserName" HeaderText="Name" />
<asp:BoundField DataField="Status" HeaderText="Status" />
</Columns>
</asp:GridView>
<asp:TextBox ID="txtCount" runat="server"></asp:TextBox>
</div>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM UserStatus", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
gvStatus.DataSource = dt;
gvStatus.DataBind();
}
}
}
}
protected void StatusChanged(object sender, EventArgs e)
{
if ((sender as CheckBox).Checked)
{
string status = (sender as CheckBox).Text.ToLower() == "pending" ? "no" : "yes";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM UserStatus WHERE Status = @Status", con))
{
cmd.Parameters.AddWithValue("@Status", status);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
gvStatus.DataSource = dt;
gvStatus.DataBind();
int count = dt.Rows.Count;
txtCount.Text = count.ToString();
}
}
}
}
else
{
this.BindGrid();
}
}
Screenshot