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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajeev PunhaniPosted Mar 31, 2016, 8:00 AM
Hi Praveen,
Please send gridview structure from aspx page so that we can help you.
Nishant MittalPosted Mar 31, 2016, 4:31 AM
praveen kumarPosted Mar 31, 2016, 4:24 AM
Rajeev PunhaniPosted Mar 31, 2016, 4:13 AM
Hi Praveen,
Could you send Gridview structure.
praveen kumarPosted Mar 31, 2016, 3:55 AM
Rajeev PunhaniPosted Mar 31, 2016, 3:24 AM
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 kumarPosted Mar 31, 2016, 2:48 AM
Nishant MittalPosted Mar 31, 2016, 2:33 AM
praveen kumarPosted Mar 31, 2016, 2:24 AM
Rajeev PunhaniPosted Mar 31, 2016, 2:11 AM
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.
Nishant MittalPosted Mar 31, 2016, 1:48 AM
TimeSpan.Addreturns a new instance ofTimeSpan.praveen kumarPosted Mar 31, 2016, 1:13 AM
Nishant MittalPosted Mar 31, 2016, 12:39 AM