Solved

Displaying Multi date events in calendar control

Posted on 2011-02-22
5
830 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ASP.NET Web Form Variables being reset 2 19
Problem to open Excel file 15 44
VB.NET HttpWebRequest 12 34
ASP.NET reading ATOM 2 27
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now