c# calendar控件中如何自定义每个不同日期的悬浮文本内容

比如我想用C#calender控件实现一个排班的功能,当页面加载时可以看到一个日历,当把鼠标放在某一天上时会显示这一天已有的安排(这些数据都从sqlserver数据库中获得),当点击那一天时可以进入另一个页面,对这些安排进行更改等操作,将如何实现,请教高手
补充一下:对已有安排的显示用悬浮窗口来实现

用 calender的下面这个事件,下面代码实现的是,当进入某一月时,动态查询当前用户的日程,并显示在该日期上,对于你说的悬浮鼠标显示的话,需要进行些改动。但愿对你有所帮助。
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
CalendarDay calDay = e.Day; //控件中的日期
TableCell tc = e.Cell; //每个单元格中的日期
string nowTime = string.Empty;
if (calDay.IsOtherMonth) //判断此日期是否是其他月的
{
tc.Controls.Clear(); //清空
}
else
{

// 使单数与双数一样对应
//Label lblPace= new Label();
//if (Convert.ToInt32(calDay.DayNumberText) < 10)
//{
// lblPace.Text = " " + " " + " " + " " + " ";
//}
//else
//{
// lblPace.Text = " " + " " + " ";
//}

//加入农历日期
Label lblNLDay = new Label();
lblNLDay.Text = "<br>" + NLDay.GetLunarCalendar(calDay.Date);
//tc.Controls.Add(lblNLDay);
//加入当前的日程
nowTime = calDay.Date.ToShortDateString();

//加入链接图标
//HyperLink hlkAddSchedule = new HyperLink();
//hlkAddSchedule.ImageUrl = "~/Images/AddSchule.gif";
//hlkAddSchedule.ToolTip = "新增个人日程";
//hlkAddSchedule.NavigateUrl = "AddWorkPlan.aspx?createTime=" + calDay.Date.ToShortDateString();

HyperLink hlkSchedule =null;

//如果有日程则显示内容
List<WorkPlan> list = WorkPlanManager.GetWPByCreateTime(nowTime, 1);
if (list.Count > 0)
{
for (int i = 0; i < list.Count; i++)
{
hlkSchedule = new HyperLink();
WorkPlan wp = (WorkPlan)list[i];
string scheduleUrl = string.Format("MyWorkPlan.aspx?time=" + nowTime);
string style = "@"+wp.WTitle;
if (wp.Degree.Equals('1'))//级别为重要时
{
style = "<span color='Red'># " + wp.WTitle + "</span>";
}

if (wp.IsComplete.Equals("1"))
{
style = "<span color='Red'># " + wp.WTitle + "</span><img src='../Images/okPlan.jpg' width='20px' height='20px'/>";
}
hlkSchedule.Text = "<br>" + style + "..." + "<br>";
//hlkSchedule.NavigateUrl = scheduleUrl;
tc.Controls.Add(hlkSchedule);
}

}

//tc.Controls.Add(lblPace);
// tc.Controls.Add(hlkAddSchedule);

//tc.Controls.Add(hlkSchedule);
}
//string UId=Session
e.Cell.Attributes["onmouseover"] = "javascript:currentColor=this.style.backgroundColor; this.style.cursor='hand';backgroundColor='#AFEEEE';";
e.Cell.Attributes["onmouseout"] = "javascript:this.style.backgroundColor=currentColor;";
e.Cell.Attributes["onclick"] = "javascript:this.style.cursor='hand';window.location='ScanWorkPlan.aspx?time=" + nowTime + "&UId="+1+"';";
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-08
我不知道你用的什么日历控件,我用MonthCalendar做了一个实验。

这是部分代码:
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{
setToolTip(e.Start.ToString());
}

private void setToolTip(string text)
{
toolTip1.AutomaticDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;

toolTip1.IsBalloon = true;

toolTip1.ShowAlways = true;

toolTip1.SetToolTip(monthCalendar1, text);
}

因为没有鼠标经过的时候获取时间的事件(可以自己从新做一个自定义控件),所以暂时用DataSelected代替。追问

我用的是vs2005里面好像没有MonthCalendar控件,我用的是calender控件,后台用OnDayRender事件

相似回答