calendar日历控件实例!

做~自己de王妃 提交于 2019-12-25 13:26:45

<%@ Page Language="vb" Debug="true" %>
<%@ import namespace="system.drawing"%>
<html><head>
<script language="vb" runat="server">
'声明一个数组用与储存一年中的节日
dim holidays(12,31) as string
dim y,m,s,j as integer
sub page_load(sender as object,e as eventargs)
'将具体的节日名存入数组
 holidays(1,1)="元旦"
 holidays(2,20)="春节"
 holidays(3,8)="妇女节"
 holidays(5,1)="劳动节"
 holidays(5,4)="青年节"
 holidays(6,1)="儿童节"
 holidays(7,1)="建党节"
 holidays(8,1)="建军节"
 holidays(9,10)="教师节"
 holidays(9,28)="中秋节"
 holidays(10,1)="国庆节"
 holidays(12,25)="圣诞节"
 '用指定图形来显示选择月份和星期的标志
 calendar1.selectmonthtext="选全月" 'calendar选择月份的标签
 calendar1.selectweektext="选全周" 'calendar选择星期的标签
end sub
'选择时间下拉框的数
sub page_init(sender as object,e as eventargs) '请注意,这里使用的是page_init对象,如果用load的话,下拉框里的数就会循环几次了
for y=1980 to 2010 
 dat.items.add(y)
 next
for m=1 to 12
 mon.items.add(m)
 next
end sub

'日历控件的dayrendar事件的处理程序。
sub calendar1_dayrender(sender as object,e as dayrendereventargs)
 dim c as tablecell
 dim d as calendarday
 dim g as string
 c=e.cell '将dayrendereventargs的cell对象赋给 c
 d=e.day  '将dayrendereventargs的day对象赋给 d
 g=val(d.date.month) & val(d.date.day)
 if d.isothermonth then
  c.controls.clear '不显示非当前月份的日前
 else
  dim strholiday,strstart,strend as string
  strholiday=holidays(d.date.month,d.date.day) '获取节日名
  strstart="<br><font color=red face=宋体>" 'HTML格式语句开始部分
  strend="</font>"       'HTML格式语句结束部分
  if strholiday <> "" then '将节日名所在的日期存入C,同时设置字体颜色
   c.controls.add(new literalcontrol(strstart+strholiday+strend))
   c.forecolor=color.red
  end if
 end if
end sub
'日历控件selectionchanged事件处理程序
sub date_selected(sender as object,e as eventargs)
 label1.text="被选中的日期为:" & calendar1.selecteddate
end sub
'日历控件的visiblemonthchanged事件处理程序
sub month_changed(sender as object,e as monthchangedeventargs)
 label1.text="当前显示的月为:" & e.previousdate.month
 label1.text & ="月,当前月为:" & e.newdate.month & "月。"
end sub
'处理选择年
sub year1(sender aS object,e as eventargs)
 dim y as string=cstr(dat.selecteditem.text)
 dim m as string=cstr(mon.selecteditem.text) 
 calendar1.Visibledate= m &"/01/" & y 
end sub
'处理选择月
sub mon1(sender aS object,e as eventargs)
 dim y as string=cstr(dat.selecteditem.text)
 dim m as string=cstr(mon.selecteditem.text) 
 calendar1.Visibledate= m &"/01/" & y 
end sub
</script>
<body>
<asp:Literal ID="txt" runat="server">
<strong>calendar 控件实例</strong>
</asp:Literal>
<form id="form" method="post" runat="server">
<asp:Calendar ID="calendar1" runat="server"
 OnDayRender="calendar1_dayrender"
 OnSelectionChanged="date_selected"
 OnVisibleMonthChanged="month_changed"
 ShowGridLines="true"
 BorderWidth="1"
 Font-Name="宋体"
 Font-Size="14px"
 Width="500px"
 TitleStyle-BackColor="#009999"
 TitleStyle-ForeColor="darkblue"
 TitleStyle-Font-Size="16px"
 TitleStyle-Font-Bold=""
 DayHeaderStyle-BackColor=""
 DayHeaderStyle-ForeColor="#CCCCCC"
 DayStyle-VerticalAlign="top"
 DayStyle-Height="55"
 DayStyle-Width="55"
 NextPrevFormat="FullMonth"
 NextPrevStyle-BackColor="#009999"
 SelectionMode="DayWeekMonth"
 SelectedDayStyle-BackColor="#009999"
 FirstDayOfWeek="Monday"
 WeekendDayStyle-ForeColor="#FF0000"/></asp:Calendar>
请选择时间:
 <%--选择下拉框--%>
<asp:DropDownList ID="dat" runat="server" AutoPostBack="true" OnSelectedIndexChanged="year1">
</asp:DropDownList>&nbsp;&nbsp;
<asp:DropDownList ID="mon" runat="server" AutoPostBack="true" OnSelectedIndexChanged="mon1">
</asp:DropDownList><br>
<asp:Label ID="label1" runat="server"/>
</form>

</body></head></html>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!