This is a migrated thread and some comments may be shown as answers.

[Solved] Rad Calender issue

2 Answers 102 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 17 Jun 2009, 03:13 PM
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 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 22 Jun 2009, 08:49 AM
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.
0
Kevin
Top achievements
Rank 1
answered on 22 Jun 2009, 09:09 AM
I have Found another way from the Courseware that is available from the site thank you for your help on this issue
Tags
Calendar
Asked by
Kevin
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or