简体   繁体   English

Calendar_VisibleMonthChanged仅返回已更改的月份

[英]Calendar_VisibleMonthChanged returns only only months changed

I have this code: 我有以下代码:

protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
    DateTime date = Convert.ToDateTime(Calendar1.VisibleDate.ToString("M, y"));
    Label2.Text = date.ToString("MM, yyyy") + "г.";
}

And when i change month in Calendar, Label2.text allways consists of months of 2015(current) year, even if i change month in Calendar 13 times. 当我在Calendar中更改月份时,即使我在Calendar中更改月份13次,Label2.text也始终包含2015(当前)年的月份。 For example, in Calendar i see 1st January 2016, but in label still 1st January 2015. 例如,在“日历”中,我看到2016年1月1日,但在标签中仍然看到2015年1月1日。

You may have found a bug. 可能发现了一个错误。 In any event, this works: 无论如何,这是可行的:

Label2.Text = e.NewDate.ToString("MM, yyyy") + "г.";

As per the comment on @Steve your code should be 根据对@Steve的评论,您的代码应为

protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e) 
{
    ShowYear(e); 
} 
protected void ShowYear(MonthChangedEventArgs e) 
{ 
    Label2.Text = e.NewDate.ToString("MM, yyyy") + "г."; 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM