您的位置:首页 > 编程语言 > ASP

asp.net3.5 csharp: How to show HTML content in calendar tooltip?

2010-06-29 18:42 531 查看
from: http://dotnet.itags.org/web-forms/133110/

csharp代码

1 <% Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
5 <head runat="server">
6 <title>geovindu</title>
7 <style type="text/css">
8 #dhtmltooltip{
9 position: absolute;
10 width: 150px;
11 border: 2px solid black;
12 padding: 2px;
13 background-color: lightyellow;
14 visibility: hidden;
15 z-index: 100;
16 /*Remove below line to remove shadow. Below line should always appear last within this CSS*/
17 filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135);
18 }
19 </style>
20
21 </head>
22 <body>
23 <div id="dhtmltooltip"></div>
24 <script type="text/javascript">
25
26 /***********************************************
27 * Cool DHTML tooltip script- ? Dynamic Drive DHTML code library (www.dynamicdrive.com)
28 * This notice MUST stay intact for legal use
29 * Visit Dynamic Drive athttp://www.dynamicdrive.com/ for full source code
30 ***********************************************/
31
32 var offsetxpoint=-60 //Customize x offset of tooltip
33 var offsetypoint=20 //Customize y offset of tooltip
34 var ie=document.all
35 var ns6=document.getElementById && !document.all
36 var enabletip=false
37 if (ie||ns6)
38 var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
39
40 function ietruebody(){
41 return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
42 }
43
44 function ddrivetip(thetext, thecolor, thewidth){
45 if (ns6||ie){
46 if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
47 if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
48 tipobj.innerHTML=thetext
49 enabletip=true
50 return false
51 }
52 }
53
54 function positiontip(e){
55 if (enabletip){
56 var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
57 var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
58 //Find out how close the mouse is to the corner of the window
59 var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
60 var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
61
62 var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
63
64 //if the horizontal distance isn't enough to accomodate the width of the context menu
65 if (rightedge<tipobj.offsetWidth)
66 //move the horizontal position of the menu to the left by it's width
67 tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
68 else if (curX<leftedge)
69 tipobj.style.left="5px"
70 else
71 //position the horizontal position of the menu where the mouse is positioned
72 tipobj.style.left=curX+offsetxpoint+"px"
73
74 //same concept with the vertical position
75 if (bottomedge<tipobj.offsetHeight)
76 tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
77 else
78 tipobj.style.top=curY+offsetypoint+"px"
79 tipobj.style.visibility="visible"
80 }
81 }
82
83 function hideddrivetip(){
84 if (ns6||ie){
85 enabletip=false
86 tipobj.style.visibility="hidden"
87 tipobj.style.left="-1000px"
88 tipobj.style.backgroundColor=''
89 tipobj.style.width=''
90 }
91 }
92
93 document.onmousemove=positiontip
94
95 </script>
96
97 <form id="form1" runat="server">
98 <div>
99 <asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender" ToolTip="werwerwer">
</asp:Calendar>
<a href="http://reference.itags.org/reference/link/?url=http://yahoo.com" onMouseover="ddrivetip('Yahoo\'s Site', 'yellow', 250)";
onMouseout="hideddrivetip()">Yahoo</a>

</div>
</form>
</body>
</html>

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{

string url= e.SelectUrl;
e.Cell.Controls.Clear();

HyperLink link = new HyperLink();
link.Text = e.Day.Date.ToString();
link.NavigateUrl = url;

link.Attributes.Add("onMouseOver", "ddrivetip('2333', 'yellow', 250)");
link .Attributes .Add ("onMouseOut","hideddrivetip()");

e.Cell.Controls.Add(link);

}
}

Demo: http://www.dusystem.com/Calendar.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: