Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-04-08
4
Medium Priority
?
477 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 2000 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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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
Screencast - Getting to Know the Pipeline
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

773 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