开发者

Counting the number of days in between in gridview

I have two tables and one is the LendTable which contains dateborrowed and datereturned columns and the other one is the PenaltyTable which contains the PenaltyAmount.

To get the PenaltyAmount, datereturned is subtracted from dateborrowed'.

So how can I get the value and bind it to PenaltyAmount column?

I m just new to programming in ASP.NET so help would be greatly appreciated. I've heard from my friends you can use 'Datediff开发者_高级运维'.

Thanks in advance!!


It can be done like...

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DataRow dr = ((DataRowView)e.Row.DataItem).Row;
        TimeSpan ts = Convert.ToDateTime(dr["datereturned"]) - Convert.ToDateTime(dr["dateborrowed"]);
        ((Label)e.Row.FindControl("PenaltyAmountLable")).Text = ((ts.TotalDays) * Convert.ToDecimal(dr["PenaltyAmount"])).ToString();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜