Click here to Skip to main content
13,089,943 members (41,969 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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);
                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.
Posted 22-Apr-13 20:16pm
Updated 22-Apr-13 23:02pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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.
Mohi Uddin Sumon 23-Apr-13 5:10am
I created datatable but the problem is that when at the second time loops go to catch. I m very worry.
@AmitGajjar 23-Apr-13 5:55am
what is the error message ?
Mohi Uddin Sumon 23-Apr-13 5:58am
I m sorry. I have solved the problem. Thank u for ur help.
@AmitGajjar 23-Apr-13 6:00am
i am glad you solved your problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100