This is probably a very simple solution but I am stumped. I am trying to render events on an asp:calendar control using LINQ. I have code behind that loads up my XDocument during Pageload and calls a dayrender event. But I can't figure out how to get my XDocument into the event argument to be tested on during the "if ..." statements. Here is the code, the commented out section is what is supposed to be run if I could get 'thismonth' into the event handler. The yellow-coloring section was just for testing.
protected void Page_Load(object sender, EventArgs e)
{
XDocument eventsXML = XDocument.Load(Server.MapPath("Events.xml"));var events = from theeventin eventsXML.Descendants("event")
selectnew
{
Organization = theevent.Element("organization").Value,
Creator = theevent.Element("creator").Value,
Name = theevent.Element("name").Value,
Description = theevent.Element("description").Value,
Location = theevent.Element("location").Value,
EventDate = DateTime.Parse(theevent.Element("Date").Element("Day").Value)
};var thismonth = from itemin events
where item.EventDate.Month == DateTime.Now.Month
select item;Calendar1.DayRender +=new DayRenderEventHandler(Calendar1_DayRender);
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (!e.Day.IsOtherMonth && !e.Day.IsWeekend) <-------- Just for testing.
e.Cell.BackColor = System.Drawing.Color.Yellow;//foreach (var item in thismonth) <------ "thismonth does not exist in this context" how do I get it here?
//{
// if (item.EventDate.Date.Equals(e.Day.Date))
// e.Cell.BackColor = System.Drawing.Color.PaleVioletRed;
//}
}
Still no progress I've given up for now. When I move the entire data-access into the Calendar1_dayrender event it just "Object not an instance" errors out on "select new"
Weldon
0 comments:
Post a Comment