Help with DataView and calendar

Hi all,

I'm trying to customize a calendar using the DayRender event. I have some code taken from ASP.NET 2.0 Unleashed which shows you how to colour the background yellow, here is the code:

If schedule.FindRows(e.Day.Date).Length > 0 Then
            e.Cell.BackColor = Drawing.Color.Yellow
End If

I have been trying to add text to the event using:

Select Case Convert.ToInt32(schedule.Item(3))
                Case 25
                    e.Cell.Controls.Add(New LiteralControl(ChrW(60) & "br" & ChrW(62) & "Event"))
End Select

The GridView is populated from an SQL DataSource:

<asp:SqlDataSource ID="srcCalendar" ConnectionString="<%$ ConnectionStrings:t2 %>" SelectCommand="Select cb.recordID,
    From dbo.trn_classBookings cb
    Left Outer Join dbo.trn_classes cl On cb.classID = cl.classID
    Left Outer Join dbo.trn_coursesMaster cm On cl.courseID = cm.courseID" runat="server">

The yellow background works, but how can I test the rows so I can show the data from the database as text on the day?

LVL 11
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
What is the problem with this line?

  e.Cell.Controls.Add(New LiteralControl(ChrW(60) & "br" & ChrW(62) & "Event"))

Is it being run?  Does it render incorrectly?

G0ggyAuthor Commented:
No, you can't access:


I'm not totaly familier with the dataview, but as you can see from the code above, I'm trying to access it like an array, which may not be correct.
Bob LearnedCommented:
If 'schedule' is a DataView, then schedule(3) would be a DataRowView, and then you would need to reference the column.  The 3 would be the index to the row number that you want use.

Select Case Val(schedule(0)("Day"))

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

G0ggyAuthor Commented:
I solved this using an example from 4Guys, what's your ideas on closing?
Bob LearnedCommented:
If you post the example that works, then I would suggest PAQ/Refund.  If you don't, then it would be Delete/Refund.

G0ggyAuthor Commented:
Ok, does refund help me? Anyway here's the code:

Protected Sub myCalendar_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles myCalendar.DayRender
        Dim nextDate As DateTime
        If Not dsHolidays Is Nothing Then
            For Each dr As DataRow In dsHolidays.Tables(0).Rows
                nextDate = CType(dr("startDate"), DateTime)
                If nextDate = e.Day.Date Then
                    e.Cell.BackColor = System.Drawing.Color.Pink
                    e.Cell.Controls.Add(New LiteralControl(ChrW(60) & "br" & ChrW(62) & "<a class='calendarLink' href='../courses/viewCourse.aspx?CID=" & dr("classID") & "'>" & dr("courseName") & "</a>"))
                End If
        End If
    End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.