• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

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

Greetings,

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

thanks
sleeper





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
            sqlDA_getEvents.Fill(dsGetEvents);
 
            // Step 08: Return dataset
            return dsGetEvents;
        }
 
        // return null if no connection string present
        return null;
	}
}

Open in new window

0
the_sleeper
Asked:
the_sleeper
  • 2
  • 2
1 Solution
 
the_sleeperAuthor Commented:
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

0
 
GreymanMSCCommented:
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

0
 
GreymanMSCCommented:
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

0
 
the_sleeperAuthor Commented:
Thanks, GreymanMSC
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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