How to get the time-span of all the datetime data in my datagridview

北战南征 提交于 2019-12-02 13:02:34

You have your time in and time out, so create a TimeSpan and run a loop:

TimeSpan timeSpan = new TimeSpan(0);
// for each data grid row calculate and add the timespan:
    timeSpan =+ time_Out.Subtract(time_In);
//

According to the information you have provided

You need to iterate through every row of a Grid. You have to do something like this:

DateTime TotalTimeOfAllRows;

for (c= 0; c < DataGridView1.Rows.Count; c++)
{
    DateTime timeIn = DataGridView1.Rows[c].FindControl("txtTimeIn").Text;
  DateTime timeOut = DataGridView1.Rows[c].FindControl("txtTimeOut").Text;
  // Here Compute Datetime TotalTime
  DataGridView1.Rows[c].FindControl("txtTotalTime").Text = TotalTime.ToString();

  // Here Add TotalTime to TotalTimeOfAllRows     

}
//If TotalTimeOfAllRows Textbox is in Datagridview too
 DataGridView1.Rows[DataGridView1.Rows.Count-1].FindControl("txtTotalTimeOFAllRows").Text = TotalTimeOfAllRows.ToString();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!