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

后端 未结 2 1616
闹比i
闹比i 2021-01-29 05:55

The scenario go\'s like that, above and this; I have a database, which I displayed on my datagridview. I already added the timespan of each row (timeIn and timeOut<

2条回答
  •  萌比男神i
    2021-01-29 06:36

    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();
    

提交回复
热议问题