zoukankan
html css js c++ java
VS2.0控件之日历《Calendar》C#
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
无标题页
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
>
控制日历的选择模式:
<
br
/>
<
asp:DropDownList
ID
="DropDownList1"
runat
="server"
AutoPostBack
="True"
OnSelectedIndexChanged
="DropDownList1_SelectedIndexChanged"
>
<
asp:ListItem
Value
="None"
>
无选择
</
asp:ListItem
>
<
asp:ListItem
Value
="Day"
>
天
</
asp:ListItem
>
<
asp:ListItem
Value
="DayWeek"
>
天、周
</
asp:ListItem
>
<
asp:ListItem
Value
="DayWeekMonth"
>
天、周、月
</
asp:ListItem
>
</
asp:DropDownList
>
<
asp:Calendar
ID
="Calendar1"
runat
="server"
BackColor
="#FFFFCC"
BorderColor
="#FFCC66"
BorderWidth
="1px"
DayNameFormat
="Shortest"
Font-Names
="Verdana"
Font-Size
="8pt"
ForeColor
="#663399"
Height
="200px"
NextMonthText
="下月"
NextPrevFormat
="ShortMonth"
OnSelectionChanged
="Calendar1_SelectionChanged"
PrevMonthText
="上月"
SelectMonthText
="选全月"
SelectWeekText
="选全周"
ShowGridLines
="True"
Width
="328px"
DayHeaderStyle-Font-Italic
="true"
OnDayRender
="Calendar1_DayRender"
OnVisibleMonthChanged
="Calendar1_VisibleMonthChanged"
>
<
SelectedDayStyle
BackColor
="#CCCCFF"
BorderStyle
="Double"
Font-Bold
="True"
/>
<
TodayDayStyle
BackColor
="#FFCC66"
ForeColor
="White"
/>
<
SelectorStyle
BackColor
="#FFCC66"
/>
<
OtherMonthDayStyle
ForeColor
="#CC9966"
/>
<
NextPrevStyle
Font-Size
="9pt"
ForeColor
="#FFFFCC"
/>
<
DayHeaderStyle
BackColor
="#FFCC66"
Font-Bold
="True"
Height
="1px"
Font-Italic
="True"
/>
<
TitleStyle
BackColor
="#990000"
Font-Bold
="True"
Font-Size
="9pt"
ForeColor
="#FFFFCC"
/>
<
WeekendDayStyle
BackColor
="LightSalmon"
/>
</
asp:Calendar
>
<
br
/>
<
br
/>
<
asp:Label
ID
="Label1"
runat
="server"
></
asp:Label
><
br
/>
选择的 月是:
<
asp:Label
ID
="Label2"
runat
="server"
></
asp:Label
><
br
/>
选择的 年是:
<
asp:Label
ID
="Label4"
runat
="server"
></
asp:Label
><
br
/>
<
br
/>
显示输入的时间
<
asp:DropDownList
ID
="ye"
runat
="server"
>
</
asp:DropDownList
>
年
<
asp:DropDownList
ID
="mo"
runat
="server"
>
</
asp:DropDownList
>
月
<
asp:DropDownList
ID
="da"
runat
="server"
>
</
asp:DropDownList
>
日
<
asp:Button
ID
="Button1"
runat
="server"
OnClick
="Button1_Click"
Text
="切"
Width
="85px"
/><
br
/>
<
br
/>
</
div
>
</
form
>
</
body
>
</
html
>
后台C#代码
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
{
string
[][] arr;
//
声明一个数组来存储一年中的节日
protected
void
Page_Load(
object
sender, EventArgs e)
{
arr
=
new
string
[
13
][];
//
数组
for
(
int
i
=
0
;i
<
13
;i
++
)
{
arr[i]
=
new
string
[
32
];
}
//
下面是储存在数组中的节日
arr[
1
][
1
]
=
"
圆蛋节
"
;
arr[
2
][
15
]
=
"
没啥节样
"
;
arr[
3
][
8
]
=
"
妇女节
"
;
arr[
4
][
15
]
=
"
没啥节样
"
;
arr[
5
][
1
]
=
"
大假哦
"
;
arr[
6
][
1
]
=
"
娃娃节
"
;
arr[
7
][
1
]
=
"
jiandang节
"
;
arr[
7
][
15
]
=
"
洪川医药正式启用
"
;
arr[
8
][
1
]
=
"
兵仔儿节
"
;
arr[
9
][
10
]
=
"
孔子节
"
;
arr[
9
][
28
]
=
"
热烈庆祝,今天是川哥的生日哈!
"
;
arr[
10
][
1
]
=
"
大假哦
"
;
arr[
11
][
15
]
=
"
没啥节样
"
;
arr[
12
][
25
]
=
"
鬼节
"
;
//
填充年月日下拉菜单
for
(
int
y
=
1980
; y
<
2050
; y
++
)
{
//
填充年下拉列表
ye.Items.Add(y.ToString());
}
for
(
int
m
=
1
; m
<
13
; m
++
)
{
//
填充月下拉列表
mo.Items.Add(m.ToString());
}
for
(
int
d
=
1
; d
<
32
; d
++
)
{
//
填充日下拉列表
da.Items.Add(d.ToString());
}
}
protected
void
DropDownList1_SelectedIndexChanged(
object
sender, EventArgs e)
{
switch
(DropDownList1.SelectedValue)
//
循环判断
{
case
"
None
"
:
//
注意是冒号
Calendar1.SelectionMode
=
CalendarSelectionMode.None;
//
设置选择方式为 没有
break
;
//
跳出循环
case
"
DayWeekMonth
"
:
Calendar1.SelectionMode
=
CalendarSelectionMode.DayWeekMonth;
break
;
case
"
DayWeek
"
:
Calendar1.SelectionMode
=
CalendarSelectionMode.DayWeek;
break
;
case
"
Day
"
:
Calendar1.SelectionMode
=
CalendarSelectionMode.Day;
break
;
}
}
protected
void
Calendar1_SelectionChanged(
object
sender, EventArgs e)
{
//
当选择一个日期时激发
Label1.Text
=
"
完整日期是 :
"
+
Calendar1.SelectedDate.ToShortDateString();
Label2.Text
=
Calendar1.SelectedDate.Month.ToString()
+
"
月
"
;
Label4.Text
=
Calendar1.SelectedDate.Year.ToString()
+
"
年
"
;
}
protected
void
Calendar1_VisibleMonthChanged(
object
sender, MonthChangedEventArgs e)
{
//
当切换到其他月的时候激发
Label1.Text
=
"
你真的要换到下个月??
"
;
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
//
指定日期事件
string
y
=
ye.SelectedValue.ToString();
//
得到年的值
string
m
=
mo.SelectedValue.ToString();
//
得到月的值
string
d
=
da.SelectedValue.ToString();
//
得到日的值
Calendar1.VisibleDate
=
Convert.ToDateTime(y
+
"
-
"
+
m
+
"
-
"
+
d);
//
指定被选中的日期
}
protected
void
Calendar1_DayRender(
object
sender, DayRenderEventArgs e)
//
注意这个事件名称是 DayRender
{
CalendarDay d
=
e.Day;
//
设置当前日期
TableCell c
=
e.Cell;
//
设置当前表格
if
(d.IsOtherMonth)
{
//
如果是其他月份的话就清除本来的节日
c.Controls.Clear();
}
else
{
try
{
string
txt
=
arr[d.Date.Month][d.Date.Day];
//
得到完整的当前[月][日]
if
(txt
!=
string
.Empty)
//
看下里面是否有东西
{
c.Controls.Add(
new
LiteralControl(
"
<br>
"
+
txt));
//
如果有的话,就在日期数字后面换行显示出来
}
}
catch
(Exception exe)
{
Response.Write(exe.ToString());
}
}
}
}
记住该记住的,忘记该忘记的,改变能改变的,接受不能改变的!
查看全文
相关阅读:
使用discourse 作为社区工具
dremio schema 更新的问题
go-mysql-server 新版本发布
开发一个dremio user_agent 解析函数
java 几个不错的user_agent 解析工具包
Docker Swarm 高可用详解
用Docker Swarm实现容器服务高可用
Docker 1.12 :认识 Swarm 模式下的节点崩溃处理
Linux下磁盘分区调整(在不使用LVM的情况下)
docker-swarm----多机容器管理
原文地址:https://www.cnblogs.com/yuanermen/p/645355.html
最新文章
dremio mysql connector 对于低版本mysql 支持中文乱码问题
dremio 自定义connector 图标
dremio sql server 自定义connector开发解决中文乱码问题
dremio sql server 查询中文的问题
规避dremio数据查询限制的一些方法
markojs ebay开源的支持基于html+组件化web app的框架
golang 几种 filter的实现包
dremio 节点监控
dremio 升级操作说明
airbyte 整体架构
热门文章
plop 方便的micro-generator framework
jsdelivr 工作原理
集成unpkg npm包发布说明
unpkg +verdaccio+ webpack 联邦实现多版本控制
unpkg docker 镜像
degit 简单项目脚手架工具
dremio prometheus监控
java 几个不错的编译器
blitz 全栈react 框架
discourse一个docker-compose 配置
Copyright © 2011-2022 走看看