在数据表中显示日期 [英] Showing Dates in a data table

查看:76
本文介绍了在数据表中显示日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在c#中查看以下代码:

我已编写以下代码以获取用户提供的日期。用户提供日期范围,我想添加7天,并显示从日期范围开始每7天的每个日期

Please look the following codes in c# :
I have written the following codes to get dates that the user provides. User provide a date range and I want to add 7 days and to show every the dates for every next every 7 days from the date range

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime dtFromDate = new DateTime();
        dtFromDate = Convert.ToDateTime("01/01/2013");
        DateTime dtToDate = new DateTime();
        dtToDate = Convert.ToDateTime("01/31/2013");
        DateTime StartDate = new DateTime();
        Label1.Text = "";
        while (dtFromDate <= dtToDate)
        {           
            if (dtFromDate == Convert.ToDateTime("01/08/2013"))
            {
               dtFromDate = dtFromDate.AddDays(1);
            }
            else
            {
                Label1.Text += dtFromDate.ToString();
                dtFromDate = dtFromDate.AddDays(7);
            }         
        }                    
    }
}



结果如下:




And the result is as follows :

1/1/2013 12:00:001/9/2013 12:00:00 AM1/16/2013 12:00:00 AM1/23/2013 12:00:00 AM1/30/2013 12:00:00 AM



但我的要求是将结果分配到数据表中。然后我将生成水晶报告。


But my requirement is to assign the result in a data table. Then I will generate crystal report.

推荐答案

您好,



您需要动态创建数据表。目前,您只是在标签中附加日期信息,但是您需要创建数据表单元格,然后在生成数据表后,您可以根据需要将其分配给数据网格。



请查看这个 [ ^ ]动态生成数据表的文章。



希望这会对你有所帮助。



祝你好运。
Hi,

You need to create dynamically data table. Currently you are just appending date information in the label but you need to create data table cells and then after generating data table you can assign it to data grid if you want.

Please check this[^] article for generating data table dynamically.

Hope this will help you.

Best Luck.


这篇关于在数据表中显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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