Hi, i want to calculate total timesapn in gridview rows in asp.net kindly help me out.
Thank you.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nishant MittalRank #692 · 3.5K reputationPosted Mar 30, 2016, 8:39 PM EDT
praveen kumar185 reputationPosted Mar 30, 2016, 9:13 PM EDT
Nishant MittalRank #692 · 3.5K reputationPosted Mar 30, 2016, 9:48 PM EDT
TimeSpan.Addreturns a new instance ofTimeSpan.Rajeev PunhaniRank #551 · 4.4K reputationPosted Mar 30, 2016, 10:11 PM EDT
Hi Praveen,
TimeSpan sum = TimeSpan.Zero;
for ( int i = 0; i < gridview1.Rows.Count; i++ )
{
sum += (TimeSpan)gridview1.Rows[i].Cells[7].Text;
}
If the above solution is helpful then,accept the answer.
praveen kumar185 reputationPosted Mar 30, 2016, 10:24 PM EDT
Nishant MittalRank #692 · 3.5K reputationPosted Mar 30, 2016, 10:33 PM EDT
praveen kumar185 reputationPosted Mar 30, 2016, 10:48 PM EDT
Rajeev PunhaniRank #551 · 4.4K reputationPosted Mar 30, 2016, 11:24 PM EDT
Hi Praveen,
TimeSpan sum = TimeSpan.Zero;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string times= ((Label)e.Row.FindControl("lbltime")).Text;
//string times= e.Row.Cells[columnIndex].Text;
sum += (TimeSpan)times ;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl = (Label)e.Row.FindControl("lblTotal");
lbl.Text = sum.ToString();
}
}
If the above solution is helpful then,accept the answer.
praveen kumar185 reputationPosted Mar 30, 2016, 11:55 PM EDT
Rajeev PunhaniRank #551 · 4.4K reputationPosted Mar 31, 2016, 12:13 AM EDT
Hi Praveen,
Could you send Gridview structure.
praveen kumar185 reputationPosted Mar 31, 2016, 12:24 AM EDT
Nishant MittalRank #692 · 3.5K reputationPosted Mar 31, 2016, 12:31 AM EDT
Rajeev PunhaniRank #551 · 4.4K reputationPosted Mar 31, 2016, 4:00 AM EDT
Hi Praveen,
Please send gridview structure from aspx page so that we can help you.