标签:
rili.aspx
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class rili : System.Web.UI.Page { protected void Page_Init(object sender, EventArgs e) { //通过循环填充年月日下拉菜单 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 Calendar1_SelectionChanged(object sender, EventArgs e) { Label1.Text = Calendar1.SelectedDate.ToShortDateString();//选则完整日期 Label2.Text = Calendar1.SelectedDate.Month.ToString() + "月";//月份 Label3.Text = Calendar1.SelectedDate.Year.ToString() + "年";//年 } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { //选则下拉列表中的值,选中None,日,周,月 switch (DropDownList1.SelectedValue) { case "None": Calendar1.SelectionMode = CalendarSelectionMode.None; break; case "Day": Calendar1.SelectionMode = CalendarSelectionMode.Day; break; case "DayWeek": Calendar1.SelectionMode = CalendarSelectionMode.DayWeek; break; case "DayWeekMonth": Calendar1.SelectionMode = CalendarSelectionMode.DayWeekMonth; break; } } 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); } } }
效果图:
1.通过选择Droplist来选择日期的类型
2.获取日历中选择的日期
3.给日历设置日期
标签:
原文地址:http://www.cnblogs.com/wangmei/p/4493241.html