Solved

Style days in a calendar DayRender event that are retrieved from a query

Posted on 2012-04-08
4
464 Views
Last Modified: 2012-04-08
Hi Guys
Using C#  I have a dataset populated with the data retrieved by the below query:

string selectStatement = "SELECT SELECT * FROM Events WHERE eventDate >= GETDATE()
";
SqlCommand selectCommand = new SqlCommand(selectStatement, con);


DataSet ds = new DataSet();
da.SelectCommand = selectCommand;
da.Fill(ds);

The above code works fine, what I am trying to do is in the calendar1_DayRender event, style each date in calendar1 that is equal to the dates retrieved by my query, the below code is a bit of a mess, please help.


protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)

DataTable dt = ds.Tables[0];

        foreach (DataRow dr in dt.Rows)
           
         for (int i = 0; i < dt.Rows.Count; i++)
            eventDate = DateTime.Parse(dr["eventDate"].ToString());
        DateTime myAppointment = e.Day.Date;
       
       
             if (eventDate == myAppointment);
        {
            e.Cell.BackColor = System.Drawing.Color.Red;
        }
0
Comment
Question by:dizzycat
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37821081
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{           
        DateTime eventDate = DateTime(dr["eventDate"]);
        DateTime myAppointment = e.Day.Date;
       
        if (eventDate == myAppointment);
        {
            e.Cell.BackColor = System.Drawing.Color.Red;
        }
}
}

Open in new window

0
 

Author Comment

by:dizzycat
ID: 37821140
In the line:

DateTime eventDate = DateTime(dr["eventDate"]);

I am getting an error:

System.DateTime is a type but used like a variable.
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37821146
oh!!! my mistake:-

DateTime eventDate = (DateTime)dr["eventDate"];
0
 

Author Closing Comment

by:dizzycat
ID: 37821150
Managed to sort out the problem thanks for your help.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

23 Experts available now in Live!

Get 1:1 Help Now