Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-04-08
4
Medium Priority
?
475 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

662 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