当前位置: 首页 > 工具软件 > Calendar.NET > 使用案例 >

.net 控件calendar 基础用法

薛云瀚
2023-12-01
1.获取其值 和天 月.年
 

Label1.Text = "完整的日期是:" + Calendar1.SelectedDate.ToShortDateString();
        Label2.Text = Calendar1.SelectedDate.Day.ToString();
        Label3.Text = Calendar1.SelectedDate.Month.ToString();
        Label4.Text = Calendar1.SelectedDate.Year.ToString()

2.设定其选择方式

 

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (DropDownList1.SelectedValue) {
            case "none":
                Calendar1.SelectionMode = CalendarSelectionMode.None;
                break;
            case "Day" :
                Calendar1.SelectionMode = CalendarSelectionMode.Day;//天方式显示
                break;
            case "WeekDay":
                Calendar1.SelectionMode = CalendarSelectionMode.DayWeek;
                break;
            case "DayWeekMonth" :
                Calendar1.SelectionMode =CalendarSelectionMode.DayWeekMonth;
                break;
        }

 

3.设定值

 

string y = ye.SelectedValue.ToString();
        string m = mo.SelectedValue.ToString();
        string d = da.SelectedValue.ToString();
        Calendar1.VisibleDate = Convert.ToDateTime(y +"-"+ m +"-" +d)

  

 类似资料: