By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,659 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,659 IT Pros & Developers. It's quick & easy.

Calendar with custom tooltip over days with events

P: n/a
I'm trying to implement a Calendar control using the OnDayRender to get
event information from an XML file. For the days that have special
events, I'd like to make the day bold red and show a tooltip with the
event descriptio nwhen the mouse is over that day.
I was able to do the color and font change for the event days, but I
cannot get the tooltip to work. For some reason the stadard calendar
tooltip with the date still shows.
Can anyone please help?

Please see code below:
------------------------------------------------------------------------
<asp:calendar id="Calendar1" runat="server" BackColor="Bisque"
SelectedDate="<%#DateTime.Today%
DayNameFormat="FirstLetter" font-size="11px"
font-names="tahoma"
selecteddaystyle-backcolor="silver"
style="border-color:#D7D7E5;" width="140"
PrevMonthText="<img src=images/cal_prevMonth.gif
border=0>"
NextMonthText="<img src=images/cal_nextMonth.gif
border=0>">
<TitleStyle BackColor="#D7D7E5"></TitleStyle>
<SelectedDayStyle BackColor="#FBE694"
ForeColor="#000000"
BorderWidth="1px" BorderColor="#BB5503">
</SelectedDayStyle>
<DayHeaderStyle Font-Bold="True"></DayHeaderStyle>
<OtherMonthDayStyle
ForeColor="#999999"></OtherMonthDayStyle>
</asp:calendar>

<script language="VB" runat="server">
Private monthDoc As System.Xml.XmlDocument = New
System.Xml.XmlDocument()
Public Sub calndr_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs)
monthDoc.Load(Server.MapPath("dayRenderData.xml"))
If e.Day.IsOtherMonth Then
Exit Sub
End If
Dim dayNumber As String = e.Day.DayNumberText
Dim dayNode As System.Xml.XmlNode = _
monthDoc.SelectSingleNode("/months/month[@index=0" & _
"]/day[@number=" & dayNumber & "]")
If Not dayNode Is Nothing Then
Dim dayItems As System.Xml.XmlNodeList =
dayNode.SelectNodes("item")
For Each dayItem As System.Xml.XmlNode In dayItems
e.Cell.Font.Bold = True
e.Cell.ForeColor = Drawing.Color.Red
e.Cell.ToolTip = dayItem.InnerXml 'THIS LINE
DOESN'T WORK
Next dayItem
End If
End Sub
</script>

Mar 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
HI!
1. try the following code (just paste it on your page):

<style type="text/css">#dhtmltooltip { BORDER-RIGHT: black 2px solid;
PADDING-RIGHT: 2px; BORDER-TOP: black 2px solid; PADDING-LEFT: 2px;
Z-INDEX: 100; FILTER:
progid:DXImageTransform.Microsoft.Shadow(color=gra y,direction=135);
VISIBILITY: hidden; PADDING-BOTTOM: 2px; BORDER-LEFT: black 2px solid;
WIDTH: 150px; PADDING-TOP: 2px; BORDER-BOTTOM: black 2px solid;
POSITION: absolute; BACKGROUND-COLOR: lightyellow }
</style>
<DIV id="dhtmltooltip"></DIV>
<SCRIPT type="text/javascript">

/***********************************************
* Cool DHTML tooltip script- C Dynamic Drive DHTML code library
(www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source
code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] :
document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")?
document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="")
tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera?
ietruebody().clientWidth-event.clientX-offsetxpoint :
window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera?
ietruebody().clientHeight-event.clientY-offsetypoint :
window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of
the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie?
ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" :
window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is
positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie?
ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px"
: window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

</SCRIPT>
2. now in the calndr_DayRender() use it the following way:

e.Cell.Attributes.Add("onMouseover", "ddrivetip('" & dayStr &
"','Khaki', 300);")
e.Cell.Attributes.Add("onMouseout", "hideddrivetip();")

where the dayStr is the variable containing the string to be displayed
in the tooltip.

regards,
krzyhoo

Mar 30 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.