PLease refer this
HTML
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Status" HeaderText="Status" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
Total presents
<asp:Label ID="lblStatusCount" runat="server" />
Namespace
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Status",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "Present");
dt.Rows.Add(2, "Mudassar Khan", "Present");
dt.Rows.Add(3, "Suzanne Mathews", "Absent");
dt.Rows.Add(4, "Robert Schidner", "Present");
GridView1.DataSource = dt;
GridView1.DataBind();
int count = 0;
foreach (GridViewRow row in this.GridView1.Rows)
{
if (row.Cells[2].Text == "Present")
{
count++;
}
}
this.lblStatusCount.Text = count.ToString();
}
}
Screenshot
