如何在GridView列中求和时间值?

时间:2016-07-03 05:55:30

标签: c#

我的GriView

This is an image 是从SQL数据库中的表填充的。

我想在页脚中运行总计。我想出了数量'数量'专栏,但我不知道如何继续“时间”#39;柱。

这是我到目前为止所做的:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        TotalQuantity += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Quantity"));
    }
    else if (e.Row.RowType == DataControlRowType.Footer)
    {
        e.Row.Cells[0].Text = "TotalQuantity";
        e.Row.Cells[0].Font.Bold = true;

        e.Row.Cells[1].Text = TotalQuantity.ToString();
        e.Row.Cells[1].Font.Bold = true;
    }
}

2 个答案:

答案 0 :(得分:0)

您需要使用$I->wantTo('Try to login with right credentials'); // step 1 $I->markFirstTimeTag(); $I->amOnPage('/user/login'); // step 2 $I->fillField('#login-form-login','admin'); // step 3 $I->fillField('#login-form-password','admin'); // step 4 $I->click('#login-form button[type=submit]'); // step 5 $I->markSecondTimeTag(); $I->calculateTheDiffFor("Login attempt"); $I->seeCurrentUrlEquals('/user/admin'); // step 6 数据结构。 System.TimeSpan列中的值可能存储为字符串,因此您需要将其转换一点并对Time求和。

TimeSpan

答案 1 :(得分:0)

可能有更好的方法可以做到这一点,但这也可以。

我们只需将您的时间添加到日期,例如<?xml version="1.0" encoding="UTF-8"?> <proxy name="proxyCalledByTopic" startOnLoad="true" trace="disable" transports="https http" xmlns="http://ws.apache.org/ns/synapse"> <target> <inSequence> <log level="custom"> <property value="********************* START METHOD *********************" name="proxyCalledByTopic"/> </log> </inSequence> <outSequence> <send/> </outSequence> <faultSequence/> </target> </proxy> 我们得到秒计数,继续计算秒数,最后我们减去

您可以执行以下操作:

2000/01/01

要获得结果:

如果您想要总秒数,请使用static double count = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DateTime tmp = Convert.ToDateTime("2000/01/01 " + DataBinder.Eval(e.Row.DataItem, "Time").ToString()); count += tmp.Subtract(Convert.ToDateTime("2000/01/01 00:00:00")).TotalSeconds; } 。如果要在底部显示总时间,请使用以下内容:

count
相关问题