Showing multi-day events in the calendar

Rate It (2)

Last post 06-24-2009 8:56 AM by epora75. 11 replies.

Sort Posts:

  • Showing multi-day events in the calendar

    02-02-2006, 7:12 PM
    • Participant
      1,680 point Participant
    • samsp
    • Member since 08-08-2002, 5:35 PM
    • Posts 330
    • AspNetTeam

    There were a couple of requests for showing multi-day events in the calendar. I took a look at the calendar code, and came up with the following fix. Note I only did some brief testing, but it seemed to work for the cases I tried.

    Firstly, you'll need the calendar project, which can be found at http://www.asp.net/StarterKits/Downloads/EventCalendar.zip

    This is a C# dll project, so you'll need vs standard or C# express sku to open it. In the EventCalendar.cs code:

    a) Add the following property. It specifies the name of the field representing the end date:

            [DefaultValue("")]
            [Themeable(false)]
            public virtual string EndDayField
            {
                get
                {
                    object o = ViewState["EndDayField"];
                    if (o != null)
                    {
                        return (string)o;
                    }
                    return String.Empty;
                }
                set
                {
                    ViewState["EndDayField"] = value;
                    if (Initialized)
                    {
                        OnDataPropertyChanged();
                    }
                }
            }
    

    b) Replace the existing versions of the following methods:

           private int CreateDataBoundChildren(System.Data.DataView dv, Table table, DateTime todaysDate, DateTime visibleDate, System.Globalization.Calendar threadCalendar)
            {
                DateTime firstDay = FirstCalendarDay(this.VisibleDate);
                dv.Table.Locale = new CultureInfo("en-US");
    
                int dayoffset = 0;
                string dayField = this.DayField;
                string endDayField = this.EndDayField;
    
                for (int iRow = 0; iRow < 6; iRow++)
                {
                    TableRow row = new TableRow();
                    table.Rows.Add(row);
    
                    for (int iDay = 0; iDay < 7; iDay++)
                    {
                        DateTime d = firstDay.AddDays(dayoffset);
    
                        //Initialize the cell
                        CalendarDay day = getDay(d, TodaysDate, visibleDate, threadCalendar);
                        TableCell cell = CreateDayCell(day);
                        row.Cells.Add(cell);
    
                        //Process real data for this day
                        dv.RowFilter = string.Format("IsNull({1},{0}) >= #{2}# AND {0}<#{3}#", dayField, endDayField, d.ToString("MM/dd/yyyy"), d.AddDays(1).ToString("MM/dd/yyyy"));
                   
                        if (dv.Count > 0 && this.DayEventTemplate != null)
                        {
                            foreach (System.Data.DataRowView drv in dv)
                            {
                                DataBoundCalendarItem dataitem = new DataBoundCalendarItem(drv, day);
                                DayEventTemplate.InstantiateIn(dataitem);
                                //add the controls to both collections
                                cell.Controls.Add(dataitem);
                                //databind the data item
                                dataitem.DataBind();
                            }
                        }
                        else if (this.DayEmptyTemplate != null)
                        {
                            DataBoundCalendarItem dataitem = new DataBoundCalendarItem(null, day);
                           DayEmptyTemplate.InstantiateIn(dataitem);
                            //add the controls to both collections
                            cell.Controls.Add(dataitem);
    
                        }
                        dayoffset++;
                    }
                }
                return 1;
            }
    

    and

        void cacheDataInViewstate(System.Data.DataView dv)
            {
                DateTime firstDay = FirstCalendarDay(this.VisibleDate);
                DateTime lastDay = EndDate(this.VisibleDate);
    
                System.Collections.Generic.Dictionary<DateTime, int> ctrlcount = new System.Collections.Generic.Dictionary<DateTime, int>();
    
                foreach (System.Data.DataRowView drv in dv)
                {              
                    DateTime startdate = ((DateTime)drv[DayField]).Date;
                    DateTime enddate = (drv[EndDayField] != DBNull.Value) ? ((DateTime)drv[EndDayField]).Date : startdate;
                    DateTime rowdate = startdate;
                    while (rowdate <= enddate)
                    {
                        if (rowdate >= firstDay && rowdate <= lastDay)
                        {
                            if (ctrlcount.ContainsKey(rowdate))
                            {
                                ctrlcount[rowdate] += 1;
                            }
                            else
                            {
                                ctrlcount[rowdate] = 1;
                            }
                        }
                        rowdate = rowdate.AddDays(1);
                    }
                }
                ViewState[ViewStateDataKey] = ctrlcount;
            }
    
    

    That should be all you need in the calendar. Build it and either reference it from the website, or copy the output to the bin directory.

    The eventscalendar.aspx page needs to be modified to query for the end data as part of the sql datasource and to set the name of the enddate field on the calendar control. For example:

    <asp:SqlDataSource id=SqlDataSource1 SelectCommand="SELECT [id], [starttime], [endtime], [title], [description] FROM [Events]" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>" runat="server"></asp:SqlDataSource>
                <ec:EventCalendar id=eventscalendar CssClass="eventmonthtable" runat="server" ShowTitle="true" EndDayField="endtime" DayField="starttime" BorderWidth="0" DataSourceID="sqldatasource1">
    ...
    </ec:EventCalendar>
    
    

    That should be all that you need to have long running events show up on each day that they occur.

  • Re: Showing multi-day events in the calendar

    02-06-2006, 4:24 PM
    • Member
      35 point Member
    • meantown2
    • Member since 02-06-2006, 9:18 PM
    • Posts 7

    Hi,

    Nice idea to post this enhancement. I pulled down the event calendar project, made the updates and I get the following error on build:

    Error 1 Using the generic type 'System.Collections.Generic.Dictionary<TKey,TValue>' requires '2' type arguments C:\Documents and Settings\x\My Documents\Visual Studio Projects\EventCalendar\EventCalendar\EventCalendar.cs 352 40 EventCalendar

    In the "void cacheDataInViewstate(System.Data.DataView dv)" function, the error is on the line:

    System.Collections.Generic.Dictionary ctrlcount = new System.Collections.Generic.Dictionary();


     

  • Re: Showing multi-day events in the calendar

    02-08-2006, 4:25 PM
    • Participant
      1,680 point Participant
    • samsp
    • Member since 08-08-2002, 5:35 PM
    • Posts 330
    • AspNetTeam
    Doh. The problem was that I just pasted code into the html editor window. I thought the generic type definitions were html as they are delimited with < >. I updated the original code.
  • Re: Showing multi-day events in the calendar

    06-30-2006, 11:10 AM
    • Member
      62 point Member
    • jimbob_texas
    • Member since 06-23-2006, 4:04 PM
    • DFW
    • Posts 19

    Slick solution!  Thanks very much.

    jr

    Like to shoot? Come see us!
    http://www.dallaspistol.com/
  • Re: Showing multi-day events in the calendar

    07-10-2006, 12:30 PM
    • Member
      455 point Member
    • jonesf222
    • Member since 12-07-2005, 3:04 AM
    • Posts 91
    Could someone please share the corrected solution for multiday EventsCalendar or better yet the dll file? Thanks
  • Re: Showing multi-day events in the calendar

    07-10-2006, 7:31 PM
    • Member
      592 point Member
    • mikedeko
    • Member since 06-23-2002, 2:39 PM
    • Posts 119
    The code listing above was corrected and works as is.
  • Re: Showing multi-day events in the calendar

    09-24-2006, 1:16 PM
    • Member
      205 point Member
    • Jim 555
    • Member since 12-04-2005, 10:07 PM
    • San Gabriel (By Los Angeles), California
    • Posts 54

    Hello,

    I just downloaded the calendar project C# codes from http://www.asp.net/StarterKits/Downloads/EventCalendar.zip

    When I clicked on "EventCalendar.csproj", I got the following message?  What does the message mean?
     


                The project location is not trusted:

                D:\Documents and Settings\My Documents\Download\EventCalendar_zip\EventCalendar

                Running the application may result in security exceptions when it
                attempts to perform actions which require full trust.

                Click OK to ignore and continue.



    Jim

     

  • Re: Showing multi-day events in the calendar

    11-01-2006, 11:05 AM
    • Member
      5 point Member
    • rta
    • Member since 11-01-2006, 4:02 PM
    • Posts 1

    Hello,

     

    When I place the dll on a Windows Sharepoint Service website it gives me an error that the file is wrong.

     What do I need to do to get this up and running on a SHarepoint website?

     kind regards

     

    robbert tames

  • Re: Showing multi-day events in the calendar

    04-29-2008, 6:33 PM
    • Member
      14 point Member
    • dfourlife
    • Member since 11-15-2007, 7:08 PM
    • Posts 75

    This is very helpful , but How can this code be adjusted so that the event description set in DayEventTemplate can span across the startdate and enddate fields?
    sort of like in outlook. any suggestions

  • Re: Showing multi-day events in the calendar

    06-16-2009, 12:28 AM
    • Member
      2 point Member
    • suvn99999
    • Member since 06-16-2009, 4:22 AM
    • Posts 1

    Hi Jim,

     Because at this time I realy need this code, but the url to download does not exist so I can not get it Can you post this project code for me?

    Thanks in advance for your help!!!

     

    suvn99999

  • Re: Showing multi-day events in the calendar

    06-16-2009, 7:39 AM
    • Member
      205 point Member
    • Jim 555
    • Member since 12-04-2005, 10:07 PM
    • San Gabriel (By Los Angeles), California
    • Posts 54

    Hello suvn99999,

    I still have the zip file that I downloaded from http://www.asp.net/StarterKits/Downloads/EventCalendar.zip back in year 2006.

    How can I deliver it to you?   Better yet, where can I post it so that eveyone  can access it?

    Jim

     

     

     

  • Re: Showing multi-day events in the calendar

    06-24-2009, 8:56 AM
    • Member
      2 point Member
    • epora75
    • Member since 06-24-2009, 8:54 AM
    • Posts 1

     Hi Jim,

    Were you able to post the EventCalendar.zip anywhere?  I have a tight deadline and was hoping to work off a base implementation.

     

    Many thanks,

    Peter

Page 1 of 1 (12 items)