Click here to Skip to main content
13,149,756 members (56,427 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I am trying to create a hotel booking calendar that selects the DateFrom and DateTo

I need to iterate through from the DateFrom to DateTo and display all these dates in the calendar, the code I have so far only selects the `DateFrom` and `DateTo` and displays them in the calendar as a label:

 protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            DateTime df = (DateTime)dr.Field<DateTime?>("DateFrom");
            DateTime dt = (DateTime)dr.Field<DateTime?>("DateTo");
 

            if (e.Day.Date == dt.Date)
            {
                Label lbl = new Label();
                lbl.BackColor = System.Drawing.Color.Gray;
                lbl.Text = "Booked From";
                e.Cell.Controls.Add(lbl);
             }
 
            if (e.Day.Date == df.Date)
            {
                Label lbl = new Label();
                lbl.BackColor = System.Drawing.Color.Gray;
                lbl.Text = "Booked To";
                e.Cell.Controls.Add(lbl);
            }
        } 
Posted 19-Dec-12 3:41am

1 solution

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

Solution 1

The solution I am using in case somebody who needs this comes across this is:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
  foreach (DataRow dr in ds.Tables[0].Rows)
  {
    DateTime df = (DateTime)dr.Field<DateTime?>("DateFrom");
    DateTime dt = (DateTime)dr.Field<DateTime?>("DateTo");
 
    if (e.Day.Date == dt.Date)
    {
        Label lbl = new Label();
        lbl.BackColor = System.Drawing.Color.Gray;
        lbl.Text = "Booked From";
        e.Cell.Controls.Add(lbl);
     }
 
    if (e.Day.Date == df.Date)
    {
        Label lbl = new Label();
        lbl.BackColor = System.Drawing.Color.Gray;
        lbl.Text = "Booked To";
        e.Cell.Controls.Add(lbl);
    }
 
    //Added Code
    if(e.Day.Date > df.Date && e.Day.Date < dt.Date)
    {
        Label lbl = new Label();
        lbl.BackColor = System.Drawing.Color.Gray;
        lbl.Text = "Day inbetween";
        e.Cell.Controls.Add(lbl);
    }
}
  Permalink  
v2

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.170924.2 | Last Updated 19 Dec 2012
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