Hi Shashikant, Thanks for you kinda response. We can Also Achieve it via Row Data bound.
<asp:TemplateField HeaderText="Salary" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label runat="server" ID="lblSalary" Text='<%#Eval("Salary")%>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label runat="server" ID="lblTotalSalary"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
TimeSpan? TotalSalary { get { return ViewState["TotalSalary"] as TimeSpan?; } set { ViewState["TotalSalary"] = value; } }
protected void Page_Load(object sender, EventArgs e)
{
TotalSalary = new TimeSpan();
}
protected void grdAttendance_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblSalary = e.Row.FindControl("lblSalary") as Label;
if (TotalSalary == TimeSpan.Zero)
{
TotalSalary = TimeSpan.Parse(lblSalary.Text);
}
else
{
TotalSalary += TimeSpan.Parse(lblSalary.Text);
}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblTotalSalary = e.Row.FindControl("lblTotalSalary") as Label;
lblTotalSalary.Text = TotalSalary.Value.ToString();
}
}