问题描述
大家好,因为我刚接触.net,我发现这个计算比较难,所以PLZ帮我解决这个问题。
我有2列empcode和他们的在另一栏加班,我希望将加班列总计并显示在文本框field.eg中,empcode为A111,加班时为05:30:00,我的代码为
int tohours,tomin;
protected void GridView2_RowDataBound(object sender,GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// for(int i = 0; i< GridView2.Rows.Count; i ++)
// {
foreach(GridView2.Rows中的GridViewRow行)
{
//标签thrs = (标签)GridView2.Rows [i] .FindControl(Overtime);
Label thrs =(Label)row.FindControl(Overtime);
TimeSpan ts蒂姆eSpan.Parse(thrs.Text);
tohours = ts.Hours;
tomin + = ts.Minutes;
}
//}
}
if(e.Row.RowType == DataControlRowType.Footer)
{
Label fthrs =(Label)e.Row.FindControl( lblTotalhrs);
fthrs.Text + =(tohours +:+ tomin).ToString();
}
}
提前致谢
Hi guys as iam new to .net ,iam finding this calculation is more difficult so plz help me to solve this.
iam having 2 columns empcode and their overtime in another column,i wanted to total the overtime column and display in a textbox field.eg,empcode as A111 and overtime as 05:30:00 and my code is
int tohours, tomin;
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//for (int i = 0; i < GridView2.Rows.Count; i++)
// {
foreach (GridViewRow row in GridView2.Rows)
{
// Label thrs = (Label)GridView2.Rows[i].FindControl("Overtime");
Label thrs = (Label)row.FindControl("Overtime");
TimeSpan ts = TimeSpan.Parse(thrs.Text);
tohours = ts.Hours;
tomin += ts.Minutes;
}
//}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label fthrs = (Label)e.Row.FindControl("lblTotalhrs");
fthrs.Text += (tohours + ":" + tomin).ToString();
}
}
Thanks in advance
推荐答案
int tohours, tomin;
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label thrs = (Label)e.FindControl("Overtime");
TimeSpan ts = TimeSpan.Parse(thrs.Text);
tohours += ts.Hours;
tomin += ts.Minutes;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label fthrs = (Label)e.Row.FindControl("lblTotalhrs");
fthrs.Text = ((tohours + (tomin / 60)) + ":" + (tomin % 60)).ToString();
}
}
这篇关于gridview中的小时和分钟总计(时间列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!