Solved

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

Posted on 2012-04-08
4
471 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Moving Visual Studio 2015 project to 2017 2 68
Need help for captcha 2 42
async questions 5 49
Manage big list of parameter list 8 25
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

759 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