We're trying to populate a Calendar for our Installation Team that shows distinct values from a query of Van Number and Install Time on each date in the calendar. We have it so there's a clickable Date in each cell that does something, and below that a Text String shows up with the Van # and Time. However this is duplicating.
We thought it was the String, but if we make build the same string and write it to the ToolTip for that Cell, it displays correctly. So it's that cell text for some reason.
Here's the relevant code:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
String Install = "";
String ToolTip = "";
Literal insta = new Literal();
Literal lit = new Literal();
e.Cell.BackColor = System.Drawing.Color.SkyBlue;
var rows = (from row in socialEvents.AsEnumerable()
where DateTime.Parse(row["InstallDate"].ToString()) >= e.Day.Date &&
DateTime.Parse(row["InstallDate"].ToString()) < e.Day.Date.AddDays(1)
select new
{
VanNum = row["VanNum"],
InstallTime = row["InstallTime"]
}).Distinct();
foreach (var row in rows)
{
String MyInstall = "";
MyInstall = "Van #: " + row.VanNum.ToString() + " / Install Time: " + row.InstallTime.ToString();
Install = Install + "<br/>" + MyInstall;
ToolTip = ToolTip + "/n" + MyInstall;
}
e.Cell.ToolTip = ToolTip;
lit.Visible = true;
e.Cell.Controls.Add(lit);
insta.Text = Install;
insta.Visible = true;
e.Cell.Controls.Add(insta);
}
e.Cell.ToolTip will display 3 rows, but the Literal insta.Text in the Cell Control will show it twice. The Literal lit seems to be adding the clickable Date (which I admit, I don't know how its doing that) which is why there's two Literal Controls. If we just write a single Literal Control then we lose the clickable Date but the Install data is still duplicated.
After testing more we found that the Control with text was being added twice. Not sure why we didn't see the date twice as well. But we found the answer here: https://forums.asp.net/t/453021.aspx?My+DayRender+event+is+happening+twice+and+I+don+t+know+why+
The DayRender event was firing twice, so removing
OnDayRender="Calendar1_DayRender"
from the ascx page removed the redundant firing and text only displayed once. I'm still unsure why the Date gets added to lit and only once, but that seems to be generated elsewhere and probably accounted for. This also explains the ToolTip working, because its getting set where the Control is being added.