calendar日曆控制項執行個體!

來源:互聯網
上載者:User

<%@ 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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.