Check this sample
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnDataBound = "GridView1_DataBound">
<Columns>
<asp:BoundField DataField="Data" HeaderText="Data" />
</Columns>
</asp:GridView>
Total: <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
OnYo: <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
Done: <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><br />
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Data");
dt.Rows.Add("ON YO");
dt.Rows.Add("ON YO");
dt.Rows.Add("ON YO");
dt.Rows.Add("ON YO");
dt.Rows.Add("DONE");
dt.Rows.Add("DONE");
dt.Rows.Add("DONE");
dt.Rows.Add("DONE");
dt.Rows.Add("DONE");
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_DataBound(object sender, System.EventArgs e)
{
Label1.Text = GridView1.Rows.Count.ToString();
int ONYO = 0;
int DONE = 0;
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
if (GridView1.Rows(i).Cells(0).Text == "ON YO")
ONYO = ONYO + 1;
if (GridView1.Rows(i).Cells(0).Text == "DONE")
DONE = DONE + 1;
}
Label2.Text = ONYO;
Label3.Text = DONE;
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim dt As New DataTable()
dt.Columns.Add("Data")
dt.Rows.Add("ON YO")
dt.Rows.Add("ON YO")
dt.Rows.Add("ON YO")
dt.Rows.Add("ON YO")
dt.Rows.Add("DONE")
dt.Rows.Add("DONE")
dt.Rows.Add("DONE")
dt.Rows.Add("DONE")
dt.Rows.Add("DONE")
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
Label1.Text = GridView1.Rows.Count.ToString()
Dim ONYO As Integer = 0
Dim DONE As Integer = 0
For i As Integer = 0 To GridView1.Rows.Count - 1
If GridView1.Rows(i).Cells(0).Text = "ON YO" Then
ONYO = ONYO + 1
End If
If GridView1.Rows(i).Cells(0).Text = "DONE" Then
DONE = DONE + 1
End If
Next
Label2.Text = ONYO
Label3.Text = DONE
End Sub