Rad Calender issue

3 posts, 0 answers
  1. Kevin
    Kevin avatar
    58 posts
    Member since:
    May 2009

    Posted 17 Jun 2009 Link to this post

    Hi I have looked at the code demos and looked at the calendar sample site and would like to know why the function that i'm trying to loosely base on day render function doesn't want to work this is my code
      TableCell currentCell = new TableCell();  
                RadCalendarDay day = new RadCalendarDay(RadCalendar1);  
                MonthView view = new MonthView(RadCalendar1);  
     
                Telerik.Web.UI.Calendar.DayRenderEventArgs e = new Telerik.Web.UI.Calendar.DayRenderEventArgs(currentCell, day,view);  
     
                DateTime CurrentDate = RadCalendar1.SelectedDate;  
                backgroundColor1 = Color.Red.Name;  
                backgroundColor = Color.Green.Name;            
     
                currentCell = e.Cell;  
                currentCell.Style["background-color"] = backgroundColor;  
     
                string Connection = "Data Source=62.197.41.101; Initial Catalog=PilotWebApp; User ID=sa; Pwd=medularis;";  
     
                SqlConnection conn = new SqlConnection(Connection);  
                SqlCommand cmd = new SqlCommand("Slot_sp_EngineerTimeslots_Group", conn);  
                cmd.CommandType = CommandType.StoredProcedure;  
                cmd.Parameters.AddWithValue("@PROPREF", strPropref);  
                cmd.Parameters.AddWithValue("@PRIORITYCODE", PRIORITYCODE);  
                cmd.Parameters.AddWithValue("@JOBLENGTH""30");  
                cmd.Parameters.AddWithValue("@TIMESLOT""AT");  
                conn.Open();  
                SqlDataReader reader = cmd.ExecuteReader();  
                DataTable dt = new DataTable();  
                dt.Load(reader);  
                DayOfMonth = DateTime.Today.Day;  
     
                int rows = dt.Rows.Count;  
                endDate = RadCalendar1.SelectedDate.AddDays(rows);  
     
                foreach (DataRow dr1 in dt.Rows)  
                {  
                    startDate = DateTime.Parse(dr1["BookedDate"].ToString());  
     
                    if (CurrentDate >= startDate.Date && CurrentDate <= endDate.Date)   
                    {  
                        Label label = new Label();  
                        label.Text = e.Day.Date.Day.ToString();  
                        label.BackColor = System.Drawing.Color.Green;  
                        e.Cell.Controls.Add(label);  
     
                        // disable the selection for the specific day  
                        RadCalendarDay calendarDay = new RadCalendarDay();  
                        calendarDay.Date = CurrentDate;  
                        calendarDay.IsSelectable = true;  
                        RadCalendar1.SpecialDays.Add(calendarDay);  
                    }  
                    CurrentDate.AddDays(1);  
                } 

    what i need it do do is colour the cells that dont fit into the if statement red is there anything that i can do?
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 22 Jun 2009 Link to this post

    Hello Kevin,

    In your code you are not getting a reference to the actual table cell for the corresponding day:

    Telerik.Web.UI.Calendar.DayRenderEventArgs e = new Telerik.Web.UI.Calendar.DayRenderEventArgs(currentCell, day,view); 

    The line above won't automatically set the currentCell object to the table cell for the give date and month view. What you need to do is implement your custom logic in the DayRender event of the calendar and use the DayRenderEventArgs to get hold of the cell for each date.

    I hope this information helps.

    Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Kevin
    Kevin avatar
    58 posts
    Member since:
    May 2009

    Posted 22 Jun 2009 Link to this post

    I have Found another way from the Courseware that is available from the site thank you for your help on this issue
Back to Top