|
Rank: Member Groups: Member
Joined: 6/8/2007 Posts: 19
|
Hi, I am using an eo calendar control, and am trying to highlight specific dates that are stored in a datatable. When one of these specific dates matches the current day, the code renders a label. However, I am finding that when there is more than 2 rows in the datatable, duplicate numbers appear for each day. eg. 1st appears as '11', 2nd appears as '22', 24th appears as '2424' etc. Is there a way to clear this, so dates appear correctly? Here is sample code...
Code: Visual Basic.NET
Sub calDRender(ByVal sender As Object, ByVal e As EO.Web.DayRenderEventArgs)
Dim lbl As New Label
Dim dtRow As DataRow
Dim dayDate As DateTime
'If the month is CurrentMonth
If Not e.Day.IsOtherMonth Then
For Each dtRow In dtCAP.Rows
If IsDate(dtRow.Item(0)) Then
dayDate = dtRow.Item(0)
If dayDate = e.Day.Date Then
lbl.Height = "16"
lbl.Width = "28"
lbl.BackColor = Color.PaleVioletRed
lbl.ForeColor = Color.White
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
Else
lbl.ForeColor = Color.Black
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
End If
Else
lbl.ForeColor = Color.Black
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
End If
Next
End If
End Sub
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, We tried similar code at here and it works fine:
Code: Visual Basic.NET
Sub calDRender(
ByVal sender As Object, ByVal e As EO.Web.DayRenderEventArgs)
Dim lbl As New Label
lbl.Height = "16"
lblWidth = "28"
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
End Sub
Can you try that and see if it works? You may want to try that in a blank page first. Thanks
|
|
Rank: Member Groups: Member
Joined: 6/8/2007 Posts: 19
|
Tried this in a new page, without the database connectivity, and still getting the same result (duplicated day numbers for each day). If you rem out the second date (dtRow = dtCAP.Rows.Add(dteDate2)), it works okay.
Code: Visual Basic.NET
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Common" %>
<%@ Import Namespace="System.Drawing" %>
<script language="VB" runat=server>
Dim dtColumn As DataColumn
Dim dtRow As DataRow
Dim dtCAP As New DataTable
Dim dteDate As DateTime = "2007-07-05"
Dim dteDate2 As DateTime = "2007-07-12"
Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
dtCAP.Clear()
dtColumn = New DataColumn("Start", GetType(String))
dtColumn.Caption = "Start Date"
dtCAP.Columns.Add(dtColumn)
dtRow = dtCAP.Rows.Add(dteDate)
dtRow = dtCAP.Rows.Add(dteDate2)
End Sub
Sub calDRender(ByVal sender As Object, ByVal e As EO.Web.DayRenderEventArgs)
Dim lbl As New Label
Dim dayDate As DateTime
Dim strCAPNo As String = ""
'If the month is CurrentMonth
If Not e.Day.IsOtherMonth Then
For Each dtRow In dtCAP.Rows
If IsDate(dtRow.Item(0)) Then
dayDate = dtRow.Item(0)
If dayDate = e.Day.Date Then
lbl.Height = "16"
lbl.Width = "28"
lbl.BackColor = Color.PaleVioletRed
lbl.ForeColor = Color.White
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
Else
lbl.ForeColor = Color.Black
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
End If
End If
Next
End If
End Sub
</script>
<%@ Register TagPrefix="eo" Namespace="EO.Web" Assembly="EO.Web" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<eo:Calendar ID="eoCal" runat="server" DisabledDates="" SelectedDates="" OnDayRender="calDRender" ControlSkinID="None" DayCellHeight="15" DayCellWidth="31" DayHeaderFormat="Short" VisibleDate="2007-07-01" OtherMonthDayVisible="True" TitleFormat="MMMM, yyyy" TitleLeftArrowImageUrl="DefaultSubMenuIconRTL" TitleRightArrowImageUrl="DefaultSubMenuIcon" >
<CalendarStyle CssText="background-color:white;border-bottom-color:Silver;border-bottom-style:solid;border-bottom-width:1px;border-left-color:Silver;border-left-style:solid;border-left-width:1px;border-right-color:Silver;border-right-style:solid;border-right-width:1px;border-top-color:Silver;border-top-style:solid;border-top-width:1px;color:#2C0B1E;padding-bottom:5px;padding-left:5px;padding-right:5px;padding-top:5px;" />
<SelectedDayStyle CssText="background-image:url('00040403');color:Brown;" />
<MonthStyle CssText="cursor:hand;font-family:Verdana;font-size:8pt;margin-bottom:0px;margin-left:4px;margin-right:4px;margin-top:0px;" />
<DayHoverStyle CssText="background-image:url('00040402');color:#1c7cdc;" />
<TitleStyle CssText="font-family:Verdana;font-size:8.75pt;padding-bottom:5px;padding-left:5px;padding-right:5px;padding-top:5px;" />
<DayHeaderStyle CssText="border-bottom: #f5f5f5 1px solid" />
<DisabledDayStyle CssText="color: gray" />
<TitleArrowStyle CssText="cursor: hand" />
<TodayStyle CssText="background-image:url('00040401');color:#1176db;" />
<FooterTemplate>
<table style="font-size: 11px; font-family: Verdana" border="0" cellSpacing="5" cellPadding="0">
<tr>
<td width="30"></td>
<td valign="center"><img src="{img:00040401}"></td>
<td valign="center">Today: {var:today:MM/dd/yyyy}</td>
</tr>
</table></FooterTemplate>
</eo:Calendar>
</div>
</form>
</body>
</html>
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Of course. :) When you have two rows in dtCAP and you are looping through all rows inside calDRender, it's obviously that the following code will be called twice:
Code: Visual Basic.NET
lbl.RenderControl(e.Writer)
So the root of the problem is that your code is rendering the same day twice.
|
|
Rank: Member Groups: Member
Joined: 6/8/2007 Posts: 19
|
All I am trying to do is highlight a variable amount of dates on the eo Calendar control, that are stored in a datatable. Are you able to offer an alternative method? I have done this with the standard asp.net calendar control, using an arraylist of dates (see sample below) - but your control works differently. Thanks in advance.
Code: Visual Basic.NET
Sub calDRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs)
'If the month is CurrentMonth
If Not e.Day.IsOtherMonth Then
' EVENTS
Dim dtEvent as DateTime
For i = 0 To aryEventDates.Count - 1
if isDate(aryEventDates.Item(i)) then
dtEvent = Convert.ToDateTime(aryEventDates.Item(i))
if aryEventDates.Item(i) = e.Day.Date then
e.Cell.BackColor = Color.PaleVioletRed
e.Cell.ToolTip = aryEventName(i).ToString
else
e.Day.IsSelectable = False
end if
end if
Next
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Try change this:
Code: Visual Basic.NET
If Not e.Day.IsOtherMonth Then
For Each dtRow In dtCAP.Rows
If IsDate(dtRow.Item(0)) Then
dayDate = dtRow.Item(0)
If dayDate = e.Day.Date Then
lbl.Height = "16"
lbl.Width = "28"
lbl.BackColor = Color.PaleVioletRed
lbl.ForeColor = Color.White
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
Else
lbl.ForeColor = Color.Black
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
End If
End If
Next
End If
To this:
Code: Visual Basic.NET
If Not e.Day.IsOtherMonth Then
For Each dtRow In dtCAP.Rows
If IsDate(dtRow.Item(0)) Then
dayDate = dtRow.Item(0)
If dayDate = e.Day.Date Then
lbl.Height = "16"
lbl.Width = "28"
lbl.BackColor = Color.PaleVioletRed
lbl.ForeColor = Color.White
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
Exit Sub
End If
End If
Next
lbl.ForeColor = Color.Black
lbl.Text = e.Day.DayNumberText
lbl.RenderControl(e.Writer)
End If
|
|
Rank: Member Groups: Member
Joined: 6/8/2007 Posts: 19
|
Thanks very much for your help.
|
|