2.0 Calendar populated from database? [modified]
-
Hi, Im really struggling to find solutions to my problem so any help would be greatly appreciated! Basically i want to create an events calendar which shows the current month. If the database holds any events for the current month these should be indicated within the calendar control on the corresponding day. I know items can be added to the calendar using the day render event but i dont know how to best use this to get data from the SQLDataAdapter etc. Thanks in advance. -- modified at 8:49 Tuesday 12th September, 2006
-
Hi, Im really struggling to find solutions to my problem so any help would be greatly appreciated! Basically i want to create an events calendar which shows the current month. If the database holds any events for the current month these should be indicated within the calendar control on the corresponding day. I know items can be added to the calendar using the day render event but i dont know how to best use this to get data from the SQLDataAdapter etc. Thanks in advance. -- modified at 8:49 Tuesday 12th September, 2006
-
you have to create runtime button controls according to the data Fetch from database attach event using delegate. u can populate function corresponding to the day\Date click as button control
Mahendra
Hi, Thanks for the reply but it makes no sense whatsoever! Please explain.
-
Hi, Thanks for the reply but it makes no sense whatsoever! Please explain.
If you just want to display text within day cell, then you can use DayRender method in your own class MyCalendar, which extends Calendar control. class MyCalendar : Calendar { private ArrayList myEvents; public MyCalendar() : base() { DayRender += new DayRenderEventHandler(myCalendar_DayRender); } protected override OnPreRender(object sender, EventArgs e) { DateTime visibleDate = (VisibleDate > new DateTime(2000, 1, 1)) ? VisibleDate : TodaysDate; myEvents = LoadEventsFromDatabase(visibleDate.Month, visibleDate.Year); } void MyCalendar_DayRender(object sender, DayRenderEventArgs e) { for(int i=0; i < myEvents.Count; i++) { if (((MyEvent)myEvents[i]).Date.Day == e.Day.Date.Day) { e.Cell.Controls.Add(new LiteralControl("
" + ((MyEvent)myEvents[i]).EventTitle); } } } } I suppose you created MyEvent class with two properties, DateTime Date and string EventTitle. And you have a method LoadEventFromDatabase, which queries database, retrieves events and transform them into ArrayList of MyEvent objects (or you can use generic List instead of ArrayList) I hope it works :) Pilo -
If you just want to display text within day cell, then you can use DayRender method in your own class MyCalendar, which extends Calendar control. class MyCalendar : Calendar { private ArrayList myEvents; public MyCalendar() : base() { DayRender += new DayRenderEventHandler(myCalendar_DayRender); } protected override OnPreRender(object sender, EventArgs e) { DateTime visibleDate = (VisibleDate > new DateTime(2000, 1, 1)) ? VisibleDate : TodaysDate; myEvents = LoadEventsFromDatabase(visibleDate.Month, visibleDate.Year); } void MyCalendar_DayRender(object sender, DayRenderEventArgs e) { for(int i=0; i < myEvents.Count; i++) { if (((MyEvent)myEvents[i]).Date.Day == e.Day.Date.Day) { e.Cell.Controls.Add(new LiteralControl("
" + ((MyEvent)myEvents[i]).EventTitle); } } } } I suppose you created MyEvent class with two properties, DateTime Date and string EventTitle. And you have a method LoadEventFromDatabase, which queries database, retrieves events and transform them into ArrayList of MyEvent objects (or you can use generic List instead of ArrayList) I hope it works :) PiloPilo, Thanks for the detailed solution. I've been away from .Net for a while now and am new to version 2.0 using VS2005. How do i go about retreiving data from the database and turning it into an array? It seemsVS2005 only allows wizard based use of the SqlDataAdapter, how do i get the data from this? Many thanks and sorry to be so demanding! :-)