Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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.
Posted 22-Apr-13 21:16pm
Edited 23-Apr-13 0:02am
v4

1 solution

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

Solution 1

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.
  Permalink  
Comments
Mohi Uddin Sumon at 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 at 23-Apr-13 5:55am
   
what is the error message ?
Mohi Uddin Sumon at 23-Apr-13 5:58am
   
I m sorry. I have solved the problem. Thank u for ur help.
@AmitGajjar at 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
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 217
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,025


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
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