本文介绍了如何在计算的日子里删除小时的小时数...... asp.net,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通过后面的代码创建一个Gridview表,

在Gridview表中,一列是从两个日期之间计算的天数,

对于列格式我在RowDataBound编写代码,

所以Days列格式没有转换,

显示Days.HH MM SS FFF也



请愿。任何人帮助我..



我尝试过:



  protected   void  Page_Load(对象发​​件人,EventArgs e)
{
// Gridview数据绑定
DataClassesDataContext db = new DataClassesDataContext();
var sumo = 来自 i db.Chech_ins
let Dys = DateTime.Now - i.IN_Date
select new
{Gues_Name = i.Room_num,
IN_Date = i.IN_Date,
Today_Date = DateTime.Now,
天= Dys,
总计= i.Tariff * 2
};
GridView1.DataSource = sumo;
GridView1.DataBind();

}



受保护 void GridView1_RowDataBound( object sender,GridViewRowEventArgs e)
{

// 用于更改列格式
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Cells [ 1 ]。Text = Convert.ToDateTime(e。 Row.Cells [ 1 ]。文本).ToString( DD-MM-YYYY);
e.Row.Cells [ 2 ]。Text = Convert.ToDateTime(e.Row.Cells [ 2 ]。文本).ToString( dd-MM-yyyy);
e.Row.Cells [ 3 ]。Text = double .Parse(e.Row .Cells [ 3 ]。Text).ToString();
e.Row.Cells [ 4 ]。Text = Convert.ToInt32(e.Row.Cells [ 4 ]文本)的ToString();
}
}
解决方案



I am was create one Gridview table through code behind,
In the Gridview table one column is for days counting from between two dates,
For the columns formate i wrote code in RowDataBound,
so in that Days column format is not converting,
It was showing Days.HH MM SS FFF also

pls. any one help me ..

What I have tried:

protected void Page_Load(object sender, EventArgs e)
    {
       // Gridview Data binding 
        DataClassesDataContext db = new DataClassesDataContext();
          var sumo = from i in db.Chech_ins
                     let Dys = DateTime.Now - i.IN_Date
                     select new
                   {   Gues_Name = i.Room_num,
                       IN_Date= i.IN_Date, 
                       Today_Date=DateTime.Now,
                       Days = Dys,
                       Total = i.Tariff * 2,
                   };
        GridView1.DataSource = sumo;
        GridView1.DataBind();
    
    }



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

       // for change the column formate
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
    
            e.Row.Cells[1].Text = Convert.ToDateTime(e.Row.Cells[1].Text).ToString("dd-MM-yyyy");
            e.Row.Cells[2].Text = Convert.ToDateTime(e.Row.Cells[2].Text).ToString("dd-MM-yyyy");
            e.Row.Cells[3].Text = double.Parse(e.Row.Cells[3].Text).ToString();
            e.Row.Cells[4].Text = Convert.ToInt32(e.Row.Cells[4].Text).ToString();
        }
    }
解决方案



这篇关于如何在计算的日子里删除小时的小时数...... asp.net,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:51