Welcome Guest Search | Active Topics | Sign In | Register

Scheduler Calender - DayRender Help. Options
Rebecca Stahr
Posted: Tuesday, May 27, 2008 2:24:27 PM
Rank: Newbie
Groups: Member

Joined: 5/13/2008
Posts: 2
Please help me. I am trying to get the calendar to fill in the cells from a SQL Database and it seems I can't get the hashtable to fill with data from the reader.

Here is my page:
Quote:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="calendarMonthView.ascx.vb" Inherits="controls_calendars_calendarMonthView" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>

<eo:callbackpanel id="CallbackPanel1" runat="server" Triggers="{ControlID:CalendarMonthView;Parameter:}" LoadingHTML="Updating..."
LoadingPanelID="calendar_title_text">
<eo:Calendar id="CalendarMonthView" runat="server" TitleTemplateScope="TextOnly" GridLineColor="207, 217, 227"
TitleFormat="MMMM, yyyy" TitleLeftArrowHtml="&amp;lt;" DayHeaderFormat="Full"
TitleRightArrowHtml="&amp;gt;" GridLineVisible="True" DayCellWidth="72" DayCellHeight="45"
GridLineFrameVisible="False">
<DayStyle CssText="BORDER-RIGHT: #eaeaea 1px solid; BORDER-TOP: #eaeaea 1px solid; FONT-SIZE: 9px; BORDER-LEFT: #eaeaea 1px solid; BORDER-BOTTOM: #eaeaea 1px solid; FONT-FAMILY: Verdana; BACKGROUND-COLOR: #eaeaea; TEXT-ALIGN: right"></DayStyle>
<TitleTemplate>
<span id="calendar_title_text">{var:visible_date:MMMM, yyyy} </span>
</TitleTemplate>
<TitleStyle CssText="padding-right: 3px; padding-left: 3px; font-weight: bold; padding-bottom: 3px; color: white; padding-top: 3px; border-bottom: #cfd9e3 1px solid; background-color: #006699; font-size: 11px; font-family: verdana;"></TitleStyle>
<CalendarStyle CssText="border-right: #cfd9e3 1px solid; border-top: #cfd9e3 1px solid; font-size: 11px; border-left: #cfd9e3 1px solid; cursor: hand; border-bottom: #cfd9e3 1px solid; font-family: verdana; background-color: #eaeaea"></CalendarStyle>
<DayHoverStyle CssText="BORDER-RIGHT: #dadada 1px solid; BORDER-TOP: #dadada 1px solid; FONT-SIZE: 9px; BORDER-LEFT: #dadada 1px solid; BORDER-BOTTOM: #dadada 1px solid; FONT-FAMILY: Verdana; BACKGROUND-COLOR: #dadada; TEXT-ALIGN: right"></DayHoverStyle>
<MonthStyle CssText="font-size: 11px; font-family: verdana;"></MonthStyle>
<DayHeaderStyle CssText="height: 17px"></DayHeaderStyle>
<FooterTemplate>Today: {var:today:MM/dd/yyyy}</FooterTemplate>
</eo:Calendar>
</eo:callbackpanel>


And here is my code behind:

Quote:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Collections
Imports System.Configuration

Partial Class controls_calendars_calendarMonthView
Inherits System.Web.UI.UserControl

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadHolidays()
End Sub 'Page_Load

#Region "Web Form Designer generated code"

Protected Overrides Sub OnInit(ByVal e As EventArgs)
'
' CODEGEN: This call is required by the ASP.NET Web Form Designer.
'
InitializeComponent()
MyBase.OnInit(e)
End Sub 'OnInit


'/ <summary>
'/ Required method for Designer support - do not modify
'/ the contents of this method with the code editor.
'/ </summary>
Private Sub InitializeComponent()
End Sub 'InitializeComponent

#End Region

'Structure to hold holiday information

Private Class Holiday
Public Title As String
Public [Date] As Date
Public Category As String
End Class 'Holiday

Private m_htHolidays As Hashtable


Private Sub LoadHolidays()
m_htHolidays = New Hashtable()

'Dim db As New DemoDB()

'Define data objects
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader

'Read the connection string from web.config
Dim connString As String = ConfigurationManager.ConnectionStrings("pediatrics").ConnectionString

'Initialize Connection
conn = New SqlConnection(connString)

'Create command queries to read data
comm = New SqlCommand("SELECT CALENDAR_DATE.CAL_DATE, CALENDAR_CATEGORY.CAL_CATEGORY, CALENDAR.CALENDAR_TITLE FROM CALENDAR_DATE INNER JOIN CALENDAR ON CALENDAR_DATE.CALENDAR_ID = CALENDAR.CALENDAR_ID INNER JOIN CALENDAR_CATEGORY ON CALENDAR.CAL_CATEGORY_ID = CALENDAR_CATEGORY.CAL_CATEGORY_ID", conn)


Try
'Open the Connection
conn.Open()

'Execute the command
reader = comm.ExecuteReader()

'Dim reader As SqlDataReader = db.ExecuteReader("select * from Holidays order by HolidayDate")
Try
While reader.Read()
Dim day As New Holiday()
day.Title = reader("CALENDAR_TITLE").ToString()
day.Date = CType(reader("CAL_DATE"), Date)
day.Category = reader("CAL_CATEGORY").ToString()
m_htHolidays(day.Date) = day
End While
Finally
CType(reader, IDisposable).Dispose()
End Try
Finally
'CType(db, IDisposable).Dispose()

'Close the connection
conn.Close()
End Try

End Sub 'LoadHolidays


Private Sub CalendarMonthView_DayRender(ByVal sender As Object, ByVal e As EO.Web.DayRenderEventArgs) Handles CalendarMonthView.DayRender
'Check if there is a matching holiday
Dim holiday As Holiday = CType(m_htHolidays(e.Day.Date), Holiday)

If holiday Is Nothing Then
e.Writer.Write(e.Day.DayNumberText)

Else
'Otherwise output the holiday information. We use
'a table here to arrange the layout
e.Writer.Write("<table border=""0"" cellSpacing=""0"" cellPadding=""0"">")
e.Writer.Write("<tr>")

'Write the day text
e.Writer.Write("<td align=""right"">")
e.Writer.Write(e.Day.DayNumberText)
e.Writer.Write("</td>")

e.Writer.Write("</tr><tr>")

'Write the holiday name
e.Writer.Write("<td colspan=""2"" align=""left""><div style=""width:70px;height:28px;overflow:hidden;line-height:14px;"">")
e.Writer.Write(holiday.Title)
e.Writer.Write("<br/>(")
e.Writer.Write(holiday.Category)
e.Writer.Write(")")
e.Writer.Write("</div></td>")


e.Writer.Write("</tr></table>")


End If
End Sub
End Class
eo_support
Posted: Tuesday, May 27, 2008 2:38:19 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,096
Hi,

Your code looks perfectly fine to me. You can follow these simple steps to trouble shoot:

1. From the Calendar point of view, all it does is to call DayRender on every day cell. So you want to check is DayRender indeed being called?
2. Your code tries to store Holiday object into a hashtable in LoadHolidays. Do you indeed get m_htHolidays filled after LoadHolidays is called?
3. Inside DayRender you try to look up a Holiday object that matches the specific day cell. Did you get any matching Holiday object?

This should help you narrow down the problem. Most likely the problem would be in step 2 and step 3 (because we tested step 1). If that's the case, you may want to ask somebody around you to help you debugging as those would have nothing to do with the DatePicker; If indeed you found out the problem is in step 1, let us know and we will take a look.

Thanks
Rebecca Stahr
Posted: Thursday, May 29, 2008 10:09:02 AM
Rank: Newbie
Groups: Member

Joined: 5/13/2008
Posts: 2
I got this working but just realized that your demo site sample code only renders one entry per day. Do you have a sample that would check for and render more than one item for each day in the DayRender?
eo_support
Posted: Thursday, May 29, 2008 11:03:11 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,096
Hi,

The point is not "render one entry per day". The point is you can render anything you want. The sample showed you how to render "one entry", but you are free to render anything there.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.