Hi Celv,
Please refer below Sample.
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="Country" HeaderText="Country" ItemStyle-Width="150" />
<asp:BoundField DataField="Status" HeaderText="Status" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
<hr />
<table>
<tr>
<td>Total Present Count Is :-</td>
<td><asp:Label ID="lblTotalPresent" Text="" runat="server" /></td>
</tr>
</table>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)),
new DataColumn("Status",typeof(string))});
dt.Rows.Add(1, "John Hammond", "United States", "Present");
dt.Rows.Add(2, "Mudassar Khan", "India", "Present");
dt.Rows.Add(3, "Suzanne Mathews", "France", "Absent");
dt.Rows.Add(4, "Robert Schidner", "Russia", "Present");
GridView1.DataSource = dt;
GridView1.DataBind();
int count = dt.Select().Where(s => s["Status"].ToString().ToUpper() == "PRESENT").Count();
// If using DataSet.
//int count = ds.Tables[0].Select().Where(s => s["Status"].ToString().ToUpper() == "PRESENT").Count();
this.lblTotalPresent.Text = count.ToString();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(3) {New DataColumn("Id", GetType(Integer)), New DataColumn("Name", GetType(String)), New DataColumn("Country", GetType(String)), New DataColumn("Status", GetType(String))})
dt.Rows.Add(1, "John Hammond", "United States", "Present")
dt.Rows.Add(2, "Mudassar Khan", "India", "Present")
dt.Rows.Add(3, "Suzanne Mathews", "France", "Absent")
dt.Rows.Add(4, "Robert Schidner", "Russia", "Present")
GridView1.DataSource = dt
GridView1.DataBind()
Dim count As Integer = dt.Select().Where(Function(s) s("Status").ToString().ToUpper() = "PRESENT").Count()
''If using DataSet.
''Dim count As Integer = ds.Tables(0).Select().Where(Function(s) s("Status").ToString().ToUpper() = "PRESENT").Count()
Me.lblTotalPresent.Text = count.ToString()
End If
End Sub
Screenshot
