When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Published: Saturday, June 05, 1999

Creating an Event Calendar
By, Christopher Miller


I have recently (both personally and professionally) found it necessary to implement a calendar within a web application. I roamed all of my favorite web developer sites for a component that offered what I needed and did not find anything very interesting.

- continued -

The best example I found is at my second favorite ASP site (second only to 4 Guys, which is of course my favorite), ASP 101. They offer a great calendar app, but it does not have very much functionality. My calendar needed to have current events that were added and edited by registered users, so I took their code and make a few modifications.

  • Click here try my example

    Lets start by getting their code and naming the page, calendar.asp. We are simply using their code as a generic starting point.

    You then need a place to store your events. I created an access database called "users". I then created a table within this database called "calendar". The calendar table has the following fields:

    Calendar
    IDAuto Number (And Primary Key)
    SubjectText
    MessageMemo
    DayNumber
    MonthNumber
    YearNumber
    AddedByText
    DateAddedDate Time

    All of the records are pretty self explanatory with the exception of the ID field. We will use this later on to display the desired event.

    Once the database is made, you then need to create your ASP pages. In this example, we will use four pages; calendar.asp, display_event.asp, add_event.asp, and edit_event.asp. You could probably get away with only two pages, but for ease-of-use, we will create four.

    Lets start with the calendar.asp page. As I mentioned earlier, we will be grabbing the bulk of the calendar code from ASP 101. We need to then include the ADO constants and connect to our databse (for more information on including ADOVBS.inc, read How to use ADOVBS.inc):

    
    <--#include file="adovbs.inc"-->
    
    Dim DB_CONNECTIONSTRING
    Dim objRecordset
    
    DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
    		      Server.Mappath("users.mdb") & ";"
    
    Set objRecordset = Server.CreateObject("ADODB.Recordset")
    objRecordset.Open "calendar", DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable
    

    We will then need to find the part of the code that writes out the days of the calendar and insert the subjects of our database with a link to the display_event.asp page. This will give the users something to click on to veiw the entire event.

    
    If Not objRecordset.BOF Then
    
       '--Move to the first record
       objRecordset.MoveFirst
    
       Do Until objRecordset.EOF
    
          '--If the years match, then check the month and days--
    
          If objRecordset.Fields("Year") = Year(dDate) Then
             If objRecordset.Fields("Month") = Month(dDate) Then
                If objRecordset.Fields("Day") = iCurrent Then
    
                   '--If everything matches the current day, then display 
    	       'the subject with the coresponding ID--
    
                   Response.Write("<br><font size=2><a href=" & _
                                  Chr(34) & "display_event.asp?ID=" & _
                                  objRecordset.Fields("ID") & Chr(34) & ">" & _
                                  objRecordset.Fields("Subject") & _
                                  "</a></font><br>")
    
                 End If
              End If
           End If
    
    
           '--If nothing matches, move to the next record and 
           'start over again--
    
           objRecordset.MoveNext
       Loop
    End If
    
    We have now displayed the subject of the correct event with the event ID appended on the URL as a query string (ex. display_event.asp?ID=10). When the user clicks on the subject of the event, we pass the event ID on to the display_event.asp page.

    Which brings us to the display event page. You need to first connect to the database (same as above). You then need to get the event ID from the query string and scroll through the database until we find the event:

    
    EventToShow = CInt(Request.QueryString("ID"))
    
    If Not objRecordset.EOF Then
       objRecordset.MoveFirst
       Do Until objRecordset.Fields("ID") = EventToShow
          objRecordset.MoveNext
       Loop
    End If
    

    We then want to correlate the displayed event with a session variable for editing and display the event:

    
    Session("EventToEdit") = EventToShow
    
    Date:
    <%
    Response.Write objRecordset.Fields("Month") & "/" & _
                   objRecordset.Fields("Day") & "/" & _
                   objRecordset.Fields("Year")
    %>
    
    Subject: 
    <%
    Response.Write objRecordset.Fields("Subject")
    %>
    
    Message: <%= objRecordset.Fields("Message") %>
    Added By: <% Response.Write objRecordset.Fields("AddedBy") & _ " on " & objRecordset.Fields("DateAdded") %>

    Do not forget to clean up your database connection after you are done with it:

    objRecordset.Close
    Set objRecordset = Nothing

    The next two pages (edit_event.asp & add_event.asp) are very similar. The only exception is that with the edit event, we want to display the excisting event within the form. As I mentioned earlier, you could probably get away with combining these two pages. The one thing you need to keep in mind is with the handling of the recorset. In the update page we need to use objRecordset.Update, while in the add_event.asp page, you will want to use objRecordset.AddNew.

    In both cases, we need to connect to the database and input the data from the form into the fields, similar to below:

    objRecordset.Fields("Subject") = Request.Form("txtSubject")
    objRecordset.Fields("Message") = Request.Form("Message")
    objRecordset.Fields("Day") = Request.Form("txtDay")
    objRecordset.Fields("Month") = Request.Form("txtMonth")
    objRecordset.Fields("Year") = Request.Form("txtYear")
    objRecordset.Fields("AddedBy") = Request.Form("txtAddedBy")
    objRecordset.Fields("DateAdded") = Now()

    There is obviously much more you can do with this example, but this will provide you with a good starting point. You may want to only allow users to edit/delete events that THEY have posted (this is where the AddedBy field comes into place). You may also want to insert a time for the event. You could event color code the days that have events posted.

    Enjoy!

    Christopher Miller
    Kyrakin@excite.com

    Attachments:

  • Click here try my example
  • The Complete Source Code to this Article (zip format)


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
    Microsoft Article: 7.0, Microsoft's Lucky Version?
    Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Windows Server 2008
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES