Solved

Displaying Multi date events in calendar control

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tool Box 2 32
Data is not showing from images 15 37
Error when loading the database 16 54
Turn on intranet settings 1 36
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

930 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

8 Experts available now in Live!

Get 1:1 Help Now