Please excuse me for my ignorance as I'm new to RadControls and ASP.Net Ajax. MY skill level for ASP.Net is at a high-beginner level, at best.
I'm trying to display d/b driven events in the RadCalendar control using RADControls for ASPNET Ajax. I can get the Calendar to render properly, but can't seem to get the Events to appear on the scheduled day.
Here's some background on my project:
ASP.Net 2.0 using C# and MS Sql 2005 database. After researching these forums and Google, I've discovered that the best way to do this with a calendar control is to make the d/b call once for each month and store the events data from the d/b into an Array or some type of collection vs. making up to 31 calls to the d/b for each day rendered in the month.
So, after discovering a few examples of how to do this in some older forum posts (previous to the release of RadCalendar for ASPNET Ajax, I believe), I was able to get a head start on how to do this.
Problem is, I'm running into a few errors at build time re: the DayRender and DefaultViewChanged events: Telerik.WebControls.Base.Calendar.Events.DayRenderEventArgs
The compiler throws an error saying:
Error 143 The type or namespace name 'Base' does not exist in the namespace 'Telerik.WebControls' (are you missing an assembly reference?)
I looked in the bin directory of my project and all I saw was the following dll's:
1) RadGrid.dll (used in a previous version of Rad Controls-still works great)
2) Telerik.Web.UI.dll
I used the automatic installation to install RadControls to my VS 2005 IDE and it appears fine in the toolbox. In design mode, I inserted the Rad Calendar control on to my page and have customized it from there.
I keep thinking that there is a way to add a reference/assembly for the Telerik.WebControls.dll to the assemble, but can't locate it anywhere.
Do I even need the Telerik.WebControls.dll in this version of RadControls for ASP.Net Ajax or will the Telerik.Web.UI.dll do the trick for me?
If yes, how do I add that reference to my project?
I've tried several times to add it from the RadControls installation folder at this location:
C:\Program Files\Telerik\RadControls for ASPNET AJAX Q2 2008\Bin
but the only dll's and files I saw in there were:
1) Telerik.Charting.dll
2) Telerik.Charting.xml
3) Telerik.Web.UI.dll
4) Telerik.Web.UI.xml
I already have the Telerik.Web.UI.dll & Telerik.Web.UI.xml files in the bin directory of my project, but can't seem to get the Telerik.WebControls.dll in there.
Can anybody help me here? What am I doing wrong?
And/or - Does anybody have a better suggestion on how to display d/b driven Event data on a RADCalendar for ASP.Net Ajax control?
Any assistance would be greatly appreciated for this rookie programmer.
Thanks
Jeff O'Connell
jboconne@iupui.edu
Here is the C# code behind page I'm using for the RadCalendar:
| using System; | |
| using System.Data; | |
| using System.Data.SqlClient; | |
| using System.Data.Odbc; | |
| using System.Configuration; | |
| using System.Collections; | |
| using System.Web; | |
| using System.Web.Security; | |
| using System.Web.UI; | |
| using System.Web.UI.WebControls; | |
| using System.Web.UI.WebControls.WebParts; | |
| using System.Web.UI.HtmlControls; | |
| using AnnieECasey.DataBase; | |
| using AnnieECasey.Lib; | |
| using Telerik.WebControls; | |
| using Telerik.Web.UI; | |
| namespace AnnieECasey | |
| { | |
| /// <summary> | |
| /// Summary description for resources_websites. | |
| /// </summary> | |
| public partial class resources_events : System.Web.UI.Page | |
| { | |
| public class EventItem | |
| { | |
| //=========================================== | |
| // Class used in building the event calendar | |
| //=========================================== | |
| private int _EventID; | |
| private System.DateTime _EventDate; | |
| private string _EventName; | |
| private string _EventDesc; | |
| private int _EventCategoryID; | |
| public EventItem(int EventID, System.DateTime EventDate, string EventName, string EventDesc, int EventCategoryID) | |
| { | |
| _EventID = EventID; | |
| _EventDate = EventDate; | |
| _EventName = EventName; | |
| _EventDesc = EventDesc; | |
| _EventCategoryID = EventCategoryID; | |
| } | |
| public int EventID | |
| { | |
| get | |
| { | |
| return _EventID; | |
| } | |
| } | |
| public System.DateTime EventDate | |
| { | |
| get | |
| { | |
| return _EventDate; | |
| } | |
| } | |
| public string EventName | |
| { | |
| get | |
| { | |
| return _EventName; | |
| } | |
| } | |
| public string EventDesc | |
| { | |
| get | |
| { | |
| return _EventDesc; | |
| } | |
| } | |
| public int EventCategoryID | |
| { | |
| get | |
| { | |
| return _EventCategoryID; | |
| } | |
| } | |
| } | |
| public void Page_Load(object sender, System.EventArgs e) | |
| { | |
| radCalEvents.SelectedDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); | |
| if (!IsPostBack) | |
| { | |
| GetEventItems(); | |
| } | |
| } | |
| // setup an array to store all of the events for the month(this is what we will access thru the DayRender event) | |
| private ArrayList EventArrayList = new ArrayList(); | |
| public void GetEventItems() | |
| { | |
| DateTime startDate = ((MonthView)radCalEvents.CalendarView).MonthStartDate; | |
| DateTime endDate = ((MonthView)radCalEvents.CalendarView).MonthEndDate; | |
| SqlDataSource1.SelectParameters["MonthStartDate"].DefaultValue = startDate.ToString(); | |
| SqlDataSource1.SelectParameters["MonthEndDate"].DefaultValue = endDate.ToString(); | |
| SqlDataReader EventReader = ((SqlDataReader)((IEnumerable)SqlDataSource1.Select(DataSourceSelectArguments.Empty))); | |
| while (EventReader.Read()) | |
| { | |
| EventItem objEvent = new EventItem((int)EventReader["nID"], Convert.ToDateTime(EventReader["dEventDate"]), EventReader["sEventName"].ToString(), EventReader["sEventDescription"].ToString(), (int)EventReader["nEventCategoryID"]); | |
| EventArrayList.Add(objEvent); | |
| } | |
| EventReader.Close(); | |
| EventReader = null; | |
| } | |
| protected void radCalEvents_DayRender(object sender, Telerik.WebControls.Base.Calendar.Events.DayRenderEventArgs e) | |
| { | |
| DateTime currentDate = ((Telerik.WebControls.Base.Calendar.Events.DayRenderEventArgs)e).Day.Date; | |
| Table table = new Table(); | |
| e.Cell.Width = 95; | |
| table.Width = e.Cell.Width; | |
| table.Height = e.Cell.Height; | |
| table.CellPadding = 0; | |
| table.CellSpacing = 0; | |
| // Build the row for the day number | |
| TableRow dateRow = new TableRow(); | |
| TableCell dateCell = new TableCell(); | |
| dateCell.Width = e.Cell.Width; | |
| dateCell.CssClass = "DayNumber"; | |
| dateCell.Text = e.Day.Date.Day.ToString(); | |
| dateRow.Cells.Add(dateCell); | |
| table.Rows.Add(dateRow); | |
| // Look in the arraylist for any events on this day | |
| foreach (EventItem objEvent in EventArrayList) | |
| { | |
| if (objEvent.EventDate == currentDate) | |
| { | |
| // Add a row for the event | |
| TableRow itemRow = new TableRow(); | |
| TableCell itemCell = new TableCell(); | |
| itemCell.CssClass = "EventCell"; | |
| itemCell.Width = e.Cell.Width; | |
| // Set up the hyperlink for the event | |
| string itemText = objEvent.EventName; | |
| HyperLink itemLink = new HyperLink(); | |
| //link to a specific page for details of the event with the eventID as the parameter | |
| itemLink.NavigateUrl = "resources_eventDetails.aspx?eventid=" + objEvent.EventID; | |
| itemLink.Text = itemText; | |
| itemLink.CssClass = "EventLink"; | |
| itemLink.ToolTip = objEvent.EventDesc; | |
| itemCell.Controls.Add(itemLink); | |
| itemRow.Cells.Add(itemCell); | |
| table.Rows.Add(itemRow); | |
| } | |
| } | |
| } | |
| protected void radCalEvents_DefaultViewChanged(object sender, Telerik.WebControls.Base.Calendar.Events.DefaultViewChangedEventArgs e) | |
| { | |
| // Select events for the month when the month changes | |
| GetEventItems(); | |
| } | |
and then here is the partial code for the ASPX page:
| <asp:SqlDataSource ID="SqlDataSource1" runat="server" |
| ConnectionString="<%$ ConnectionStrings:aec_devConnectionString %>" |
| DataSourceMode="DataReader" SelectCommand="SELECT * FROM [Event] WHERE (([dEventDate] >= @MonthStartDate) AND ([dEventDate] <= @MonthEndDate)) ORDER BY [dEventDate]"> |
| <SelectParameters> |
| <asp:Parameter Name="MonthStartDate" Type="DateTime" /> |
| <asp:Parameter Name="MonthEndDate" Type="DateTime" /> |
| </SelectParameters> |
| </asp:SqlDataSource> |
| <br /> |
| <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> |
| </telerik:RadScriptManager> |
| <br /> |
| <telerik:radajaxmanager id="RadAjaxManager1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="radCalEvents"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="radCalEvents"></telerik:AjaxUpdatedControl> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:radajaxmanager> |
| <telerik:radcalendar id="radCalEvents" runat="server" OnDayRender="radCalEvents_DayRender" OnDefaultViewChanged="radCalEvents_DefaultViewChanged" font-names="Arial,Verdana,Tahoma" |
| height="500px" width="700px" ShowRowHeaders="False" Skin="WebBlue" CellAlign="Left" CellVAlign="Top" DayNameFormat="Full" ShowOtherMonthsDays="False" SingleViewRows="7" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" EnableMultiSelect="False" NavigationCellPadding="0" PresentationType="Preview" BorderColor="SteelBlue" BorderStyle="Solid" BorderWidth="1px"> |
| <SelectedDayStyle BackColor="LightSteelBlue" ForeColor="Transparent" /> |
| <DayStyle BorderStyle="Solid" BorderWidth="1px" Font-Names="Arial" Font-Size="Medium" |
| Height="100px" Width="100px" Wrap="True" BorderColor="SteelBlue" HorizontalAlign="Left" VerticalAlign="Top" Font-Underline="True" /> |
| <OtherMonthDayStyle ForeColor="Silver" Wrap="False" BorderColor="SteelBlue" BorderStyle="Solid" BorderWidth="1px" /> |
| <TitleStyle BackColor="White" BorderColor="Transparent" Font-Names="Verdana" Font-Size="12pt" /> |
| <WeekendDayStyle BorderStyle="Solid" BorderWidth="1px" Font-Names="Arial" Font-Size="Medium" |
| Height="100px" VerticalAlign="Top" Width="100px" BorderColor="SteelBlue" HorizontalAlign="Left" Wrap="True" /> |
| <CalendarTableStyle BorderColor="Transparent" HorizontalAlign="Left" |
| VerticalAlign="Top" /> |
| </telerik:radcalendar> |