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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coloring specific rows of a ASP.NET Calendar 2

Status
Not open for further replies.

ShikkurDude

Programmer
Mar 15, 2005
55
US
I want to color alternating (even/odd) rows in a Calendar control.

Ex:
blue
yellow
blue
yellow

How do I do that, please?

Thanks!
E.
 
Private cssStyls() as string="red,blue,yellow,green".split(",")
Private cssStyleIndex as Integer=0
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender

e.Cell.Style.Item("background-color") = cssStyls(cssStyleIndex )


If e.Day.Date.DayOfWeek = DayOfWeek.Saturday
cssStyleIndex = cssStyleIndex +1
If cssStyleIndex >= cssStyls.length then cssStyleIndex =0

End If
End Sub
 
Or an alternative way; declare a variable to hold the cell ID
Code:
    Dim CurrentCellID As Integer = 1
If the cell ID is in a particular range color it one color else color it a different color:
Code:
    Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        Select Case CurrentCellID
            Case 1 To 7, 15 To 21, 29 To 35
                e.Cell.BackColor = Color.Red
            Case Else
                e.Cell.BackColor = Color.Blue
        End Select
        CurrentCellID += 1
    End Sub

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
rTomes - perfect - thanks!

ca8msm - that won't work because I'm not concerned with color-coding based on the dates, rather the first and second week, as rTomes has done. Thanks very much, though!

E.
 
Did you try my solution?

It doesn't color-code based on the dates, it color-codes based on the cell number therefore when you try it you will see that the rows have different colors.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Ca8msm, no I hadn't tried it - and I misunderstood it. Very clever! Thanks much!
E.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top