Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar Control Highlighting

Status
Not open for further replies.

M8KWR

Programmer
Aug 18, 2004
864
0
0
GB
Hi,

I have got a backend database with a list of dates, what i am trying to do is highlight the dates of the given month which is displayed on the webform - via the calendar control.

So the users knows what dates have already been taken up.

I think this sounds easy (or should be), but i am struggling to find any tutorials on this.

Many thanks.
 
I have found this following code

Code:
    Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        Dim onmouseoverStyle As String = "this.style.backgroundColor='#D4EDFF'"
        Dim onmouseoutStyle As String = "this.style.backgroundColor='@BackColor'"
        Dim rowBackColor As String = String.Empty
        Dim ExistingCellColour As System.Drawing.Color

        ExistingCellColour = e.Cell.BackColor
        MsgBox(ExistingCellColour.ToString)

        e.Cell.Attributes.Add("onmouseover", onmouseoverStyle)
        e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor))




        If Not e.Day.IsWeekend Then
            e.Cell.Attributes.Add("onmouseover", onmouseoverStyle)
            e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor))
        End If


        'If the month is CurrentMonth
        If Not e.Day.IsOtherMonth Then
            Dim dr As DataRow
            For Each dr In ds.Tables(0).Rows
                'If EventDate is not Null
                If Not dr("ONDATE") Is DBNull.Value Then
                    Dim dtEvent As DateTime = dr("ONDATE").ToString
                    'If EventDate =CalendarDate
                    If dtEvent.Equals(e.Day.Date) Then
                        e.Cell.BackColor = Color.PaleVioletRed
                    End If
                End If
            Next
            'If the month is not CurrentMonth then hide the Dates
        Else
            e.Cell.Text = ""
        End If



    End Sub

But when a date is highlighted because that date occurs in the database it is connected to, when you hover over it it, it then changes color, but then does not change back the original color, but to white..

Could anyone shed some light on this for me...
 
I haven't used this control at all, but just in taking a glance at your code, this is what I'm thinking...

1) Do you want it to change color when you mouseover? If so, what color? is it a color different than the color used to signify a date that matches a date in your database?

2) If you don't want any mouseover color changes, just comment out these lines and see if it does what you're wanting.
Code:
Dim onmouseoverStyle As String = "this.style.backgroundColor='#D4EDFF'"
        Dim onmouseoutStyle As String = "this.style.backgroundColor='@BackColor'"

e.Cell.Attributes.Add("onmouseover", onmouseoverStyle)
        e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor))

3) If you are wanting a mouseover color, I think you need to move things around like this:

Code:
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        Dim onmouseoverStyle As String = "this.style.backgroundColor='#D4EDFF'"
        Dim onmouseoutStyle As String = "this.style.backgroundColor='@BackColor'"
        Dim rowBackColor As String = String.Empty
        Dim ExistingCellColour As System.Drawing.Color
	Dim newBackColor as String = ""

        ExistingCellColour = e.Cell.BackColor
        'MsgBox(ExistingCellColour.ToString)

             
'Set your day's back color first. 

        'If the month is CurrentMonth
        If Not e.Day.IsOtherMonth Then
            Dim dr As DataRow
            For Each dr In ds.Tables(0).Rows
                'If EventDate is not Null
                If Not dr("ONDATE") Is DBNull.Value Then
                    Dim dtEvent As DateTime = dr("ONDATE").ToString
                    'If EventDate =CalendarDate
                    If dtEvent.Equals(e.Day.Date) Then
                        e.Cell.BackColor = Color.PaleVioletRed
			newBackColor = e.Cell.BackColor
                    End If
                End If
            Next
            'If the month is not CurrentMonth then hide the Dates
        Else
            e.Cell.Text = ""
        End If


'Now set your mouseover colors
	
	 If Not e.Day.IsWeekend Then
            e.Cell.Attributes.Add("onmouseover", onmouseoverStyle)
	    if newBackColor = "" then 
		e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor))
	    else e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", newBackColor))
	    end if

        End If


	e.Cell.Attributes.Add("onmouseover", onmouseoverStyle)
	if newBackColor = "" then
		e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor))
	else
		e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", newBackColor))
	end if 

    End Sub

This is completely untested... and may not even work, but give it a shot and let me know.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top