473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Event Calendar with two events on the same day

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.
Aug 28 '08 #1
6 2231
hal wrote:
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.

You are setting the e.cell.text to a value which will overlay any
previous entries. On each entry for a day you need to concatonate the
value. You will have to check if any entries are already there and if
they are concatonate rather than just setting the value.

LS
Aug 28 '08 #2
I'm having the same issue to solve!
Could you, please, show an example?
Thank you in advance!
Adriana
"Lloyd Sheen" wrote:
hal wrote:
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.


You are setting the e.cell.text to a value which will overlay any
previous entries. On each entry for a day you need to concatonate the
value. You will have to check if any entries are already there and if
they are concatonate rather than just setting the value.

LS
Aug 29 '08 #3
"Adriana" <Ad*****@discussions.microsoft.comwrote in message
news:E4**********************************@microsof t.com...

[top-posting corrected]
>>if (e.Day.Date == dt)
{
e.Cell.Text = row["day"].ToString() + "<br/>" +
row["message"].ToString().Trim();
}

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.

You are setting the e.cell.text to a value which will overlay any
previous entries. On each entry for a day you need to concatonate the
value. You will have to check if any entries are already there and if
they are concatonate rather than just setting the value.

I'm having the same issue to solve!
Could you, please, show an example?
if (e.Day.Date == dt)
{
e.Cell.Text += row["day"].ToString() + "<br />" +
row["message"].ToString().Trim() + <br /><br />;
}

Notice also <br /instead of <br/>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 29 '08 #4
Thank you for your quick reply! But my code it's different and I don't know
what to do! Please, help me again! Thank you a lot!

Here is my code
==============================================
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Calendar Calendar1;
protected DataSet dsHoliday = new DataSet("holiday");
private void Page_Load(object sender, System.EventArgs e)
{
dsHoliday.ReadXml("s://home/zabeo/web/calendario/holidays.xml");
DataGrid1.DataSource = dsHoliday;
DataGrid1.DataMember = "holiday";
DataGrid1.DataBind();
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Calendar1.DayRender += new
System.Web.UI.WebControls.DayRenderEventHandler(th is.Calendar1_DayRender);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Calendar1_DayRender(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
DataGrid1.DataSource = dsHoliday;
e.Day.IsSelectable = false;

foreach (DataRow myDataRow in dsHoliday.Tables["holiday"].Rows)
{
string s = myDataRow["Date"].ToString();
string c = myDataRow["Cor"].ToString();
string d = myDataRow["Description"].ToString();
DateTime holiday_date = DateTime.Parse(s);

Style holidayStyle = new Style();
holidayStyle.BorderWidth = 1;
holidayStyle.Font.Bold = true;
holidayStyle.BorderColor =
System.Drawing.ColorTranslator.FromHtml("#"+c+"");
holidayStyle.ForeColor =
System.Drawing.ColorTranslator.FromHtml("#000000") ;

if ((e.Day.Date == holiday_date) && (!e.Day.IsOtherMonth))
{
e.Cell.ApplyStyle(holidayStyle);
e.Day.IsSelectable = true;
}
}
}
}
}
==============================================

"Mark Rae [MVP]" wrote:
"Adriana" <Ad*****@discussions.microsoft.comwrote in message
news:E4**********************************@microsof t.com...

[top-posting corrected]
>if (e.Day.Date == dt)
{
e.Cell.Text = row["day"].ToString() + "<br/>" +
row["message"].ToString().Trim();
}

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.

You are setting the e.cell.text to a value which will overlay any
previous entries. On each entry for a day you need to concatonate the
value. You will have to check if any entries are already there and if
they are concatonate rather than just setting the value.
I'm having the same issue to solve!
Could you, please, show an example?

if (e.Day.Date == dt)
{
e.Cell.Text += row["day"].ToString() + "<br />" +
row["message"].ToString().Trim() + <br /><br />;
}

Notice also <br /instead of <br/>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 29 '08 #5
"Adriana" <Ad*****@discussions.microsoft.comwrote in message
news:43**********************************@microsof t.com...

[please don't top-post]
>>I'm having the same issue to solve!
Could you, please, show an example?

if (e.Day.Date == dt)
{
e.Cell.Text += row["day"].ToString() + "<br />" +
row["message"].ToString().Trim() + <br /><br />;
}

Thank you for your quick reply! But my code it's different and I don't
know
what to do! Please, help me again! Thank you a lot!
Here is my code
foreach (DataRow myDataRow in dsHoliday.Tables["holiday"].Rows)
{
d = myDataRow["Description"].ToString();
}
Step back for a minute and look at what the code above is doing.

It says "walk through each of the rows in my datatable (one at a time) and,
each time, populate a string variable with one of the fields from that row".

And that's your problem. Each time your code moves to the next row, it
overwrites the value in the string variable which it populated in the
previous row.

So...

string d = String.Empty;
foreach (DataRow myDataRow in dsHoliday.Tables["holiday"].Rows)
{
d += myDataRow["Description"].ToString() + <br />";
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 29 '08 #6
Hi again... Maybe it's easy showing you what I need to do:

I have this calendar: http://www.zabeo.com.br/calendario/webform1.aspx

As you can see there in datagrid, holiday 1, 2 and 3 are in the same day,
with different colors, and I must use them in holidayStyle.BorderColor one
for each, in the same day.

What I need to do is exactly what is in this page bellow:

http://www.xpe.com.br/?on=16&in=8&cid=Rio%20De%20Janeiro|3653&estado_id= RJ

The calendar style shows borders colors (one for each event even in the same
day, creating borders from inside to outside...

I'd be very greatfull if you can help me to solve this!
"Mark Rae [MVP]" wrote:
"Adriana" <Ad*****@discussions.microsoft.comwrote in message
news:43**********************************@microsof t.com...

[please don't top-post]
>I'm having the same issue to solve!
Could you, please, show an example?

if (e.Day.Date == dt)
{
e.Cell.Text += row["day"].ToString() + "<br />" +
row["message"].ToString().Trim() + <br /><br />;
}
Thank you for your quick reply! But my code it's different and I don't
know
what to do! Please, help me again! Thank you a lot!
Here is my code
foreach (DataRow myDataRow in dsHoliday.Tables["holiday"].Rows)
{
d = myDataRow["Description"].ToString();
}

Step back for a minute and look at what the code above is doing.

It says "walk through each of the rows in my datatable (one at a time) and,
each time, populate a string variable with one of the fields from that row".

And that's your problem. Each time your code moves to the next row, it
overwrites the value in the string variable which it populated in the
previous row.

So...

string d = String.Empty;
foreach (DataRow myDataRow in dsHoliday.Tables["holiday"].Rows)
{
d += myDataRow["Description"].ToString() + <br />";
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 29 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Assaf Weinberg | last post by:
Using ASP.NET web form with VB.NET I have a page with a calendar control that onSelectionChanged builds a table control showing the events scheduled for the selected calendar days. One of the...
3
by: Aymer | last post by:
i created a new button object. how do i attach an event on it? thanx for your help. Dim cc As ColorConverter = new ColorConverter() Dim b = new button() b.ID = "SelectedDate" b.BorderStyle...
1
by: Dan | last post by:
In response to... DSAsteve@aol.com 6/20/2003 post wc_fl@NOSPAM.hotmail.com 3/26/2003 post ....The javascript event calendar found at http://www.scriptcalendar.com satsifies both...
2
by: Sam Miller | last post by:
Hi, I have a button event that won't fire. I left it on Friday and it worked fine. I came back in on Monday and it won't fire. I tried putting another button and just putting a...
3
by: JoakimR | last post by:
Hello, I have a problem with events not firing. I've created a web user control which renders a calendar using a table control. In two cells I'm adding LinkButtons for "prev/next month". However,...
3
by: someone | last post by:
I don't know if this is the correct group to post to, but if I am in the wrong group please redirect me. I am not a programmer but a web master. I am looking for a java applette/javascript that...
1
by: Dabbler | last post by:
I'm trying to customize calendar days using data in a table. Some days may have corresponding rows in the table giving counts for that day. I'm not clear on when I should get the data from the...
6
by: caine | last post by:
I have a clickable calendar, which user can select the day that they want to view the news linking to. My calendar has the clickable event day, but once the user click it, the day selected could...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.