Solved

Displaying Multi date events in calendar control

Posted on 2011-02-22
5
839 Views
Last Modified: 2012-05-11
Hi,

I am using calendar control which has a property of Dayfield to display the events in calendar. I am currently associating this dayfield property to database column field "EventStartDate" and I have another field name "EventEndDate". So earlier we need to display the events based on start date but now some of the events are spanning for months and needs to be render in the calendar since it reaches the end date. The values of eventstart and end date is specified by the user while creating events.

Is there any way that i can configure the Dayfield property to display all the dates between EventStartDate and  EventEndDate?? or there is any other way to configure asp calendar contol to achieve the same result??

Thanks in Advance!!
0
Comment
Question by:InorbitalWeb
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34960375
I believe that you can achieve the effect that you need by handling the DayRender event.

Example:

Calendar.DayRender Event
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.dayrender.aspx

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>DayRender Event Example</title>
<script language="C#" runat="server">

      void DayRender(Object source, DayRenderEventArgs e) 
      {

         // Change the background color of the days in the month
         // to yellow.
         if (!e.Day.IsOtherMonth && !e.Day.IsWeekend)
            e.Cell.BackColor=System.Drawing.Color.Yellow;

         // Add custom text to cell in the Calendar control.
         if (e.Day.Date.Day == 18)
            e.Cell.Controls.Add(new LiteralControl("<br />Holiday"));

      }

   </script>

</head>

<body>

   <form id="form1" runat="server">

      <h3>DayRender Event Example</h3>

      <asp:Calendar id="calendar1" 
                    OnDayRender="DayRender"
                    runat="server">

         <WeekendDayStyle BackColor="gray">
         </WeekendDayStyle>

      </asp:Calendar>

   </form>

</body>
</html>
   

Open in new window

0
 

Author Comment

by:InorbitalWeb
ID: 34960435
Thanks for the reply but this is not what i want to accomplish in my calendar. I don't want to highlight any cells of calendar. Check at the url http://www2.heritagetrust.on.ca/EWG/Events.aspx when hover over the event on date 16 that event is from feb to april and i want it to render the same event, same style that is title of the event till April.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34960629
In the DayRender event, you can do anything you want to the cell, since you have a reference in e.Cell.  I don't believe that the calendar supports what you want any other way (I could be wrong, though, so don't quote me on that)...
0
 

Author Comment

by:InorbitalWeb
ID: 34962478
Even in this day render event i am not quite sure how i am going to get the list of dates between starting date and ending date of an event to render the same event for those all the dates??
And populate the cells matching to those list of dates with the same event

Any ideas for this situation??

Thanks!!
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 34963122
If you look at how the calendar is rendered (pictured below in IE 8 Developer Tools), each cell is a <td> element.  

The DayRender event handler is defined with DayRenderEventArgs.  That class has the Day and Cell properties.  With the Day property, you can check the date for the cell, and with the Cell property, you can modify the cell contents, such as adding a <div> element with anchors, breaks, headers, etc.

DayRenderEventArgs
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dayrendereventargs.aspx
Screenshot.png
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question