C# Newbie HowTo: Wire a DataSet to a Calendar Control

Posted on 2008-11-17
Last Modified: 2012-05-05

I have created a dataset of events in a SQL Dbase. (See Code Sample). Now I'm trying to figure out how to wire it to the Calendar Control so as to have matching events display for the correct day. I've been all over the web looking for a good resource. Cant find any.

Please outline the steps I need to take and show a code example (for us "Greenhorns").


using System;

using System.Configuration;

using System.Data;

using System.Data.SqlClient;

using System.Collections.Generic;

using System.Web;

/// <summary>

/// Summary description for calendarDataObject

/// </summary>

public class calendarDataObject


    // declare method to get events

	public DataSet getEvents()


		// Step 01: Get conn string from web.config

        string CalConn = ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;

        // Step 02: Test connection string

        if(CalConn != null)


            // Step 03: Create a SqlConnection object

            SqlConnection objConn = new SqlConnection(CalConn);

            // Step 04: Create an SQL Query

            string qryGetEvents = "SELECT * FROM tbl_events";

            // Step 05: Create a SqlDataAdapter

            SqlDataAdapter sqlDA_getEvents = new SqlDataAdapter(qryGetEvents,CalConn);

            // Step 06: Create a dataset 

            DataSet dsGetEvents = new DataSet();

            // Step 07: Fill dataset


            // Step 08: Return dataset

            return dsGetEvents;


        // return null if no connection string present

        return null;



Open in new window

Question by:the_sleeper

    Author Comment

    Here is where im drawing a blank.

    Getting an error stating that the DataSet (dsGetEvents) does not exist in the current context.

    Little Help?

        protected void calEventCalendar_DayRender(object sender, DayRenderEventArgs e)
            // display events here...
            if (dsGetEvents != null) 
             // do something

    Open in new window

    LVL 16

    Accepted Solution

    The Cell and Day properties  of the DayRenderingEventArg contain what you need.
     protected void calEventCalendar_DayRender(object sender, DayRenderEventArgs e)
            // display events here...
            if (dsGetEvents != null) 
               // find the date
               datarow DayRow =dsGetEvents.Table(0).Rows.Find(e.Day.Date)
               if (DayRow != null)
                  //fill the cell, format it, et cetera.  
                  //Play with the settings
                  e.Cell.Text = R.Item("columnname").ToString

    Open in new window

    LVL 16

    Expert Comment

    Opps.  Obviously that R should have been the DayRow object, found by matching the primary key to the e.Day.Date.
    e.Cell.Text = DayRow.Item("columnname").ToString

    Open in new window


    Author Closing Comment

    Thanks, GreymanMSC

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now