Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. display booked dates in red color in calender

display booked dates in red color in calender

Scheduled Pinned Locked Moved Database
graphicshelplearning
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 8664010
    wrote on last edited by
    #1

    hi i am disabling all past dates and remaining dates in green color with the following code

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {

    if (e.Day.Date < DateTime.Today)
    {

            e.Day.IsSelectable = false;
    

    e.Cell.ForeColor = System.Drawing.Color.Gray;
    }
    else
    {
    e.Cell.ForeColor = System.Drawing.Color.Green;
    }

    } i have two dropdownlists ddlFrom and ddlTo.i vil select dates from these dropdownlists to book a room in a hotel.the dates fromdate to todate should appear in red color...any help is appreciated

    P 1 Reply Last reply
    0
    • U User 8664010

      hi i am disabling all past dates and remaining dates in green color with the following code

      protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
      {

      if (e.Day.Date < DateTime.Today)
      {

              e.Day.IsSelectable = false;
      

      e.Cell.ForeColor = System.Drawing.Color.Gray;
      }
      else
      {
      e.Cell.ForeColor = System.Drawing.Color.Green;
      }

      } i have two dropdownlists ddlFrom and ddlTo.i vil select dates from these dropdownlists to book a room in a hotel.the dates fromdate to todate should appear in red color...any help is appreciated

      P Offline
      P Offline
      Pallavi Waikar
      wrote on last edited by
      #2

      try this .First get from and to date in two variable then compare them

      protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
      {
      DateTime FromDate =Convert.ToDateTime(ddlFrom.SelectedValue);
      DateTime ToDate =Convert.ToDateTime(ddlTo.SelectedValue);

      if(e.Day.Date >= FromDate && e.Day.Date <= ToDate )
      {
      e.Cell.BackColor = System.Drawing.Color.Red;
      }
      }

      U 1 Reply Last reply
      0
      • P Pallavi Waikar

        try this .First get from and to date in two variable then compare them

        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
        DateTime FromDate =Convert.ToDateTime(ddlFrom.SelectedValue);
        DateTime ToDate =Convert.ToDateTime(ddlTo.SelectedValue);

        if(e.Day.Date >= FromDate && e.Day.Date <= ToDate )
        {
        e.Cell.BackColor = System.Drawing.Color.Red;
        }
        }

        U Offline
        U Offline
        User 8664010
        wrote on last edited by
        #3

        it doesn't work

        P 1 Reply Last reply
        0
        • U User 8664010

          it doesn't work

          P Offline
          P Offline
          Pallavi Waikar
          wrote on last edited by
          #4

          it is working!!!!!!....have u set dropdownlists autopostback property to true...for this code it is required

          U 1 Reply Last reply
          0
          • P Pallavi Waikar

            it is working!!!!!!....have u set dropdownlists autopostback property to true...for this code it is required

            U Offline
            U Offline
            User 8664010
            wrote on last edited by
            #5

            now i have been instructed to use textboxes... now i am using the following code protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) {if (e.Day.Date < DateTime.Today) { e.Day.IsSelectable = false; e.Cell.ForeColor = System.Drawing.Color.Gray; } else { e.Cell.ForeColor = System.Drawing.Color.Green; } if (e.Day.Date >= FromDate && e.Day.Date <= ToDate) { e.Cell.ForeColor = System.Drawing.Color.Red; } } protected void Button1_Click(object sender, EventArgs e) { FromDate = DateTime.ParseExact(txtFrom.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); ToDate = DateTime.ParseExact(txtTo.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } when i run the application the dates which user enters are appearing in red color in calender...but the pbm i am facing is i vil stop running the application & once again re-run application...this time user entered dates are not in red color....they are in green color. the same pbm i faced when i was using dropdownlist....even now also, the same issue i am getting...even when i stop & rerun the application user entered dates should appear in red color...by seeing red color in calender user comes to know that those dates are already booked...so he vil enter other dates..when the user clicks on calender image ,all past dates shoud be disabled....and booked dates in red color and rest of the dates in green color...at the bottom of the page indication is given to user that gray colored dates are not selectable,red colored dates are already booked and green colored dates are available for booking....this is the concept i am using...pls guide me how to solve my issue....

            P 1 Reply Last reply
            0
            • U User 8664010

              now i have been instructed to use textboxes... now i am using the following code protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) {if (e.Day.Date < DateTime.Today) { e.Day.IsSelectable = false; e.Cell.ForeColor = System.Drawing.Color.Gray; } else { e.Cell.ForeColor = System.Drawing.Color.Green; } if (e.Day.Date >= FromDate && e.Day.Date <= ToDate) { e.Cell.ForeColor = System.Drawing.Color.Red; } } protected void Button1_Click(object sender, EventArgs e) { FromDate = DateTime.ParseExact(txtFrom.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); ToDate = DateTime.ParseExact(txtTo.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } when i run the application the dates which user enters are appearing in red color in calender...but the pbm i am facing is i vil stop running the application & once again re-run application...this time user entered dates are not in red color....they are in green color. the same pbm i faced when i was using dropdownlist....even now also, the same issue i am getting...even when i stop & rerun the application user entered dates should appear in red color...by seeing red color in calender user comes to know that those dates are already booked...so he vil enter other dates..when the user clicks on calender image ,all past dates shoud be disabled....and booked dates in red color and rest of the dates in green color...at the bottom of the page indication is given to user that gray colored dates are not selectable,red colored dates are already booked and green colored dates are available for booking....this is the concept i am using...pls guide me how to solve my issue....

              P Offline
              P Offline
              Pallavi Waikar
              wrote on last edited by
              #6

              is it possible to check e.Cell.ForeColor in if then ur problem may solve.. try it for example and u have store this booked dates in database ..use this link for help http://msdn.microsoft.com/en-us/library/ms228044(v=vs.90).aspx[^]

              protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
              {
              //do databse connectivity
              //run while loop store this fromdate and todate in two variable
              //do same thing as u have done to display in red fore
              if (e.Day.Date < DateTime.Today)
              {

              e.Day.IsSelectable = false;
              e.Cell.ForeColor = System.Drawing.Color.Gray;
              }
              else
              {
              if(e.Cell.ForeColor != System.Drawing.Color.Red)
              e.Cell.ForeColor = System.Drawing.Color.Green;
              }
              if (e.Day.Date >= FromDate && e.Day.Date <= ToDate)
              {
              e.Cell.ForeColor = System.Drawing.Color.Red;
              }
              }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups