Solved

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

Posted on 2012-04-08
4
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

763 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