自定义NextMonth CallenderControll按钮错误

时间:2015-06-04 11:47:09

标签: c# asp.net

所以我需要制作一个自定义的Next / prev按钮,我几乎让它工作了jsut有一个小问题,在我的标签中显示正确的数字由于某种原因它显示了callender显示的那一天之前如果它的12月它会在标签上显示第11个我认为它与PostBack的东西我只是无法弄清楚在经过几个小时的挫折之后我会尝试在这里寻求帮助这是我到目前为止所拥有的

源代码后端

private int Month;
private int Year;
private DateTime Date;

void DayRender(Object source, DayRenderEventArgs e)
{
    // Change the background color of the days in the month
    // to yellow.
    if (!e.Day.IsOtherMonth && !e.Day.IsWeekend)
        e.Cell.BackColor = System.Drawing.Color.Yellow;

    // Add custom text to cell in the Calendar control.
    if (e.Day.Date.Day == 18)
        e.Cell.Controls.Add(new LiteralControl("<br />Holiday"));
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Date = DateTime.Now;
        Calendrier.VisibleDate = Date;
        Month = Date.Month;
        Session["Month"] = Month;
        Year = Date.Year;
    }
    MonthLabel.Text = Session["Month"].ToString();
}
// when next button is being clicked
protected void NextMonth_Command(object sender, CommandEventArgs e)
{
    int SessionMonth;

    SessionMonth = Convert.ToInt32(Session["Month"]);
    SessionMonth++;
    Session["Month"] = SessionMonth;
    ChangeCallender(2000, SessionMonth);
}

// method to add Date to Callender
private void ChangeCallender(int year, int month)
{
    DateTime date = new DateTime(year , month, 1);
    Calendrier.VisibleDate = date;
}

0 个答案:

没有答案