asp.net中gridview中的datetime列的小计和总数 [英] subtotal and total of datetime column in gridview in asp.net

查看:66
本文介绍了asp.net中gridview中的datetime列的小计和总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要在gv中找到datetime列的小计和总数,我可以为



整数值,但找到日期时间的差异,任何人都可以帮助我





我有日期时间列的模板字段



这是我的代码:

Hi guys,

I need to find subtotal and total of datetime column in gv,i could do for the

integer values but find diff for datetime, can anyone plz help me


Iam having template field for datetime column

here is my piece of code:

TimeSpan totalsum;
int tohrs, tomin;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
            {
                nric= (DataBinder.Eval(e.Row.DataItem, "Nric").ToString());
                double tmpTotal = Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "OTAmount").ToString());
                Total += tmpTotal;
                GrTotal += tmpTotal;



                TimeSpan t = new TimeSpan();

                foreach (GridViewRow row in GridView1.Rows)
                {
                    TimeSpan ts = TimeSpan.Parse(row.Cells[6].Text);

                   // t = t + ts;
                    tohrs = ts.Hours;
                    tomin = ts.Minutes;

                }
               
                totalsum = TimeSpan.Parse(tohrs.ToString());
            }
if (e.Row.RowType == DataControlRowType.Footer)
            {

                Label lblTotalqty = (Label)e.Row.FindControl("lblfota");
                lblTotalqty.Text = GrTotal .ToString();




                Label fr = (Label)GridView1.FooterRow.FindControl("lblfot");
                fr.Text = totalsum.ToString();
            }
} 

推荐答案

添加OP自己给出的解决方案。



RowCreated 中我有以下代码

Adding the solution given by OP hiself/herself.

In the RowCreated I have the following code
bool Row = false;
if ((id != null) && (DataBinder.Eval(e.Row.DataItem, "id") != null))
{
    if (id != (DataBinder.Eval(e.Row.DataItem, "id").ToString()))
     
    Row = true;
    }
    
    if ((id != null) && (DataBinder.Eval(e.Row.DataItem, "id") == null))
    {
        Row = true;
        rowIndex = 0;
    }
     
    if (Row)
    {
        GridView GridView1 = (GridView)sender;
        GridView1.HeaderRow.BackColor = System.Drawing.Color.Orange;
        GridViewRow NewTotalRow = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Insert);
        NewTotalRow.Font.Bold = true; 
        TableCell HeaderCell1 = new TableCell();
        HeaderCell1.ColumnSpan = 6;
        NewTotalRow.Cells.Add(HeaderCell);
        HeaderCell1 = new TableCell();
        HeaderCell1.HorizontalAlign = HorizontalAlign.Right;
        HeaderCell1.Text = tohrs.ToString();
        NewTotalRow.Cells.Add(HeaderCell1);
        GridView1.Controls[0].Controls.AddAt(e.Row.RowIndex + rowIndex, NewTotalRow);
        rowIndex++;
        tohrs = 0;
    }
}


这篇关于asp.net中gridview中的datetime列的小计和总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆