Welcome Guest Search | Active Topics | Sign In | Register

Calendar dayrender background color Options
lance
Posted: Wednesday, August 27, 2008 9:59:20 AM
Rank: Newbie
Groups: Member

Joined: 8/13/2008
Posts: 7
How do I set this programatically? I want to set the background color of a day based on a condition. I tried to use this in the DayRender event.

string dayId = "dayId_" + EO.Web.Calendar.DateToString(e.Day.Date);
string color = "background-color:red";
string html="myhtml"

html = string.Format(html, dayId, color);
e.Writer.Write(html);
eo_support
Posted: Wednesday, August 27, 2008 10:15:30 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

You will need to change "myhtml" To some sort of real format string that would produce a HTML element. For example, something like <div id="{0}" style="{1"}>something</div>. For detailed information, you will want to check .NET reference about string formatting:

http://msdn.microsoft.com/en-us/library/26etazsy(VS.80).aspx

Two additional notes:
1. You may not want to use EO.Web.Calendar.DateToString(e.Day.Date) to produce an element ID. DateToString returns a text in the form of "yyyy-mm-dd" and the "-" in between might cause some problems for you;
2. You certainly want to display some sort of information based on e.Day.Date, either directly or indirectly. In your case, your Calendar will always display a fixed "myhtml" for every day cell. In the DIV example we give above, it will always display a fixed "something" for every day cell. Neither is of any practical use;

The key for DayRender is that the Calendar provides an empty cell and you are responsible to fill the cell with whatever HTML code you would like. So practically whatever you would like to implement has little to do with the Calendar. Just imagine how you would do it with regular HTML without the Calendar and then move that into DayRender event.

Hope this helps.

Thanks
lance
Posted: Wednesday, August 27, 2008 11:30:54 AM
Rank: Newbie
Groups: Member

Joined: 8/13/2008
Posts: 7
The "myhtml" is obviously not html. I have actual html in my code but didn't include it in my post. As far as using EO.Web.Calendar.DateToString(e.Day.Date), I got that code from the scheduler demo page in your download so I assumed that it was proper to use it.


My question regards how to set the background color of the cell. How do I get access to the cell?
eo_support
Posted: Wednesday, August 27, 2008 11:45:55 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Ah. Sorry about that. I do not think you can access the containing day cell inside DayRender event handler. The idea of custom rendering is that you will be filling each cell, so you can always use your content to "fill" the cell and disregard anything on the cell itself. For example, if the cell is a 30 by 30 TD element and you would like it to have red background color for it, you can:

1. Render a 30 by 30 DIV in your DayRender event;
2. Place this DIV inside the cell TD. This step is automatic, which means you do not need do anything to enable this step;
3. Set background color on the DIV element you rendered;

This way you will have a 30 by 30 red block inside the cell, which would produce the same visual result as if you set background color directly on the containing day cell.

So the answer to "how to set the background color of the cell" is to "fill the cell with another element and set background color on that element".

Note you only need to do this if you were to have different colors for different dates (for example, if you want to display some dates as red because they are not available). If you want all dates to have the same background color, you would simply set DayCellStyle on the Calendar object.

Please let us know if this clears the question. Please feel free to let us know if you still have any more questions.

Thanks
lance
Posted: Wednesday, August 27, 2008 12:01:10 PM
Rank: Newbie
Groups: Member

Joined: 8/13/2008
Posts: 7
I think I can work with that. BTW, what is the proper way to get the element id?
eo_support
Posted: Wednesday, August 27, 2008 12:08:45 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

The sample has the correct code and you can copy it from there. Note the full code is like this:

Code: C#
string dayId = "dayId_" + EO.Web.Calendar.DateToString(e.Day.Date);
dayId = dayId.Replace('-', '_');


You only posted the first line, so I was concerned that you may have missed the second line. As long as you put the second line in there should be no problem.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.