[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 712
  • Last Modified:

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,
      cb.classID,
      cb.userID,
      cb.bookingStatus,
      cl.courseID,
      cl.startDate,
      cm.courseName
    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">
</asp:SqlDataSource>

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?

TIA.
           
0
G0ggy
Asked:
G0ggy
  • 3
  • 3
1 Solution
 
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?

Bob
0
 
G0ggyAuthor Commented:
No, you can't access:

schedule.item(3)

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.
0
 
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"))

Bob
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
G0ggyAuthor Commented:
I solved this using an example from 4Guys, what's your ideas on closing?
0
 
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.

Bob
0
 
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
            Next
        End If
    End Sub

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now