相关疑难解决方法(0)

如何删除日历的最后一周

我不确定为什么其他人之前没有问过这个问题.但是你注意到asp:Calendar最后会显示额外的一周吗?

例如,如果VisibleMonth设置为2010-03-01,FirstDayOfWeek设置为Sunday:它将显示6周.

  1. 2月28日至3月6日
  2. 3月7日至3月13日
  3. 3月14日至3月20日
  4. 3月21日至3月27日
  5. 3月28日至4月3日
  6. 4月4日至4月10日

我想知道为什么微软显示完全在四月份的最后一行.我试图在网上搜索一个房产,但它似乎并不存在.

我能想到的唯一解决方案是覆盖Pre_Render并检查所有个别日期,如果它们仍在VisibleDate的一周内.但当然这是一个极端的检查,因为控件的每次渲染都显示出来.

这是我的工作.

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
    int dayOfWeek = Convert.ToInt16(e.Day.Date.DayOfWeek);
    int compensate = dayOfWeek - Convert.ToInt16(DayOfWeek.Sunday);
    DateTime WeekStart = e.Day.Date.AddDays(-1 * compensate);
    DateTime WeekEnd = WeekStart.AddDays(6);

    // If the start and end of the week does not have relevance to the current month
    if (WeekStart.Month != Calendar1.VisibleDate.Month &&
        WeekEnd .Month != Calendar1.VisibleDate.Month)
    {
        e.Cell.Text = "";
        e.Cell.Height = 0;
        e.Cell.Visible = false;
    }
}
Run Code Online (Sandbox Code Playgroud)

asp.net calendar

6
推荐指数
1
解决办法
3466
查看次数

标签 统计

asp.net ×1

calendar ×1