Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
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.
Posted
Updated 22-Apr-13 23:02pm
v4

1 solution

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.
 
Share this answer
 
Comments
Sumon562 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 ?
Sumon562 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900