Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,800 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,339 people online right now. Registration is fast and FREE... Join Now!




how to add calendar control in asp.net

 
Reply to this topicStart new topic

how to add calendar control in asp.net

mesarita
21 Sep, 2008 - 11:25 PM
Post #1

New D.I.C Head
*

Joined: 21 Sep, 2008
Posts: 1

vb.net coding:

CODE

Imports System.Data.OleDb
Imports System.Data

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            '  Generates report for current year
            lblCalendar.Text = "<table width='600px'>"
            Dim horizontalRepeat As Integer = 3     '   number of months in horizontal direction
            Dim month As Integer

            For month = 1 To 12
                If (month Mod horizontalRepeat = 1) Then
                    lblCalendar.Text += "<tr valign='top'>"
                End If

                lblCalendar.Text += "<td>" + generateCalendar(month, 2007) + "</td>"

                If (month Mod horizontalRepeat = 0) Then
                    lblCalendar.Text += "</tr>"
                End If
            Next

            lblCalendar.Text += "</table>"
        End If
    End Sub

    Private Function generateCalendar(ByVal month As Integer, ByVal year As Integer) As String
        '  generates the calendar as per the booking status
        Dim wholeCalendar(5, 6) As Integer
        Dim weeks As Integer = 0
        Dim day As String = ""
        Dim tmpDate As DateTime
        Dim myDate As Integer

        For myDate = 1 To 31
            Try
                tmpDate = New DateTime(year, month, myDate)
                If (day = "Saturday") Then
                    weeks += 1
                End If
                day = tmpDate.DayOfWeek.ToString()

                If (day = "Sunday") Then
                    'If (wholeCalendar(weeks, 0) > 0) Then weeks += 1
                    wholeCalendar(weeks, 0) = myDate
                ElseIf (day = "Monday") Then
                    'If (wholeCalendar(weeks, 1) > 0) Then weeks += 1
                    wholeCalendar(weeks, 1) = myDate
                ElseIf (day = "Tuesday") Then
                    'If (wholeCalendar(weeks, 2) > 0) Then weeks += 1
                    wholeCalendar(weeks, 2) = myDate
                ElseIf (day = "Wednesday") Then
                    'If (wholeCalendar(weeks, 3) > 0) Then weeks += 1
                    wholeCalendar(weeks, 3) = myDate
                ElseIf (day = "Thursday") Then
                    'If (wholeCalendar(weeks, 4) > 0) Then weeks += 1
                    wholeCalendar(weeks, 4) = myDate
                ElseIf (day = "Friday") Then
                    'If (wholeCalendar(weeks, 5) > 0) Then weeks += 1
                    wholeCalendar(weeks, 5) = myDate
                ElseIf (day = "Saturday") Then
                    'If (wholeCalendar(weeks, 6) > 0) Then weeks += 1
                    wholeCalendar(weeks, 6) = myDate
                End If
            Catch ex As Exception
                Exit For
            End Try
        Next

        '   Generates the HTML calendar
        Dim htmlCalendar As String = ""
        Dim objEventsDAO As New EventsDAO()
        Dim dt As DataTable
        Dim i As Integer, j As Integer

        htmlCalendar += "<table class='calendarFrame' cellspacing=0>"
        htmlCalendar += "<tr class='calendarMonthYear' style='text-align: center;'><td colspan='7'>" + getMonthName(month) + " " + year.ToString() + "</td></tr>"
        htmlCalendar += "<tr class='calendarDay' style='text-align: center;'> <td>Sun</td>  <td>Mon</td>  <td>Tue</td>  <td>Wed</td>  <td>Thu</td>  <td>Fri</td>  <td>Sat</td> </tr>"

        For i = 0 To 5
            htmlCalendar += "<tr>"

            For j = 0 To 6
                If wholeCalendar(i, j) > 0 Then
                    dt = objEventsDAO.GetEvent(wholeCalendar(i, j), month, year)
                    If (dt.Rows.Count > 0) Then
                        Dim toolTip As String = dt.Rows(0)("Event").ToString()

                        htmlCalendar += "<td class='hasEvent' title=""" + toolTip + """>" + wholeCalendar(i, j).ToString() + "</td>"
                    Else
                        htmlCalendar += "<td class='hasNoEvent'>" + wholeCalendar(i, j).ToString() + "</td>"
                    End If
                Else
                    htmlCalendar += "<td class='hasNoEvent'> </td>"
                End If
            Next

            htmlCalendar += "</tr>"
        Next
        htmlCalendar += "</table>"

        '   Close database connection
        objEventsDAO.CloseConnection()

        '   returns the generated HTML calendar
        Return htmlCalendar

    End Function

    Private Function getMonthName(ByVal month As Integer) As String
        Dim months() As String = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}

        Return months(month - 1)
    End Function

End Class

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Add Calendar Control In Asp.net
23 Sep, 2008 - 11:57 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 01:52PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month