H
hal
Hello All,
I got this code somewhere, so i'm not even sure if this is the best
way to do this. Basically what i want is to display events in an
asp.net calendar control which i'm able to do, but not when i have two
events on the same day. I'm getting the data for the events from an
XML file. Here's my code.
aspx page just has the calendar control.
code behind page:
public partial class Calendar : System.Web.UI.Page
{
private DataSet _ds;
protected void Page_Load(object sender, EventArgs e)
{
_ds = new DataSet();
_ds.ReadXml(Server.MapPath("Calendar.xml"));
}
protected void Calendar1_DayRender(object sender,
DayRenderEventArgs e)
{
foreach (DataRow row in _ds.Tables[0].Rows)
{
DateTime dt = DateTime.Parse(row["date"].ToString());
if (e.Day.Date == dt)
{
e.Cell.Text = row["day"].ToString() + "<br/>" +
row["message"].ToString().Trim();
}
}
}
}
XML Page
<?xml version="1.0" encoding="utf-8" ?>
<root>
<data>
<date>8/30/2008</date>
<day>30</day>
<message>Test1</message>
</data>
<data>
<date>8/30/2008</date>
<day>30</day>
<message>Test2</message>
</data>
</root>
The second event always replaces the first event, so in the calendar
control it only displays the one event. Any help on how to get the
calendar control to display both events will be appreciated.
I got this code somewhere, so i'm not even sure if this is the best
way to do this. Basically what i want is to display events in an
asp.net calendar control which i'm able to do, but not when i have two
events on the same day. I'm getting the data for the events from an
XML file. Here's my code.
aspx page just has the calendar control.
code behind page:
public partial class Calendar : System.Web.UI.Page
{
private DataSet _ds;
protected void Page_Load(object sender, EventArgs e)
{
_ds = new DataSet();
_ds.ReadXml(Server.MapPath("Calendar.xml"));
}
protected void Calendar1_DayRender(object sender,
DayRenderEventArgs e)
{
foreach (DataRow row in _ds.Tables[0].Rows)
{
DateTime dt = DateTime.Parse(row["date"].ToString());
if (e.Day.Date == dt)
{
e.Cell.Text = row["day"].ToString() + "<br/>" +
row["message"].ToString().Trim();
}
}
}
}
XML Page
<?xml version="1.0" encoding="utf-8" ?>
<root>
<data>
<date>8/30/2008</date>
<day>30</day>
<message>Test1</message>
</data>
<data>
<date>8/30/2008</date>
<day>30</day>
<message>Test2</message>
</data>
</root>
The second event always replaces the first event, so in the calendar
control it only displays the one event. Any help on how to get the
calendar control to display both events will be appreciated.