如何删除上周日历 [英] How to Remove the Last Week Of a Calendar

查看:119
本文介绍了如何删除上周日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么其他人都没有问过这一点。但你有没有注意到,在asp:日历显示一个额外的一周结束

例如,如果VisibleMonth设置为2010-03-01和Firstdayofweek可至周日:
它会显示6周。


  1. 2月28日至3月6日

  2. 三月七日至3月13日

  3. 3月14日至三月20日

  4. 3月21日至3月27日

  5. 3月28日至4月3日

  6. 4月4日至4月10日

我想知道为什么微软给出了最后一排它完全是在四月。我试图搜索网络的属性,但它似乎并没有被现有的。

这是我能想到的唯一的解决办法是重写pre_Render并检查所有个人的日期,如果他们仍然是VisibleDate的一周内。但是,当然,这是一个极端的检查,因为每个控制渲染显示它。

下面是我的工作,各地。

 保护无效Calendar1_DayRender(对象发件人,DayRenderEventArgs E)
{
    INT一周中的某天= Convert.ToInt16(e.Day.Date.DayOfWeek);
    INT补偿=一个dayOfWeek - Convert.ToInt16(DayOfWeek.Sunday);
    日期时间WeekStart = e.Day.Date.AddDays(-1 *补偿);
    周末的DateTime = WeekStart.AddDays(6);    //如果一周的开始和结束不具有相关性的当前月份
    如果(WeekStart.Month = Calendar1.VisibleDate.Month和放大器;!&安培;
        周末.Month!= Calendar1.VisibleDate.Month)
    {
        e.Cell.Text =;
        e.Cell.Height = 0;
        e.Cell.Visible = FALSE;
    }
}


解决方案

很不错。与大多数的浏览器,但用的fugly的Chrome 11.0.696.71及Windows版Safari(在Mac上没有带测试)

有关某些月份的日历控件显示额外的一周在每月的开始。 (当本月1日是星期的第一天)。

当您设置e.cell.Visible =虚假不渲染元素。因此,在镀铬你最终的行< TR>< / TR> 。 Chrome的渲染这是一个空白行。因为我不认为有一种方法,通过日历控件设置TR元素高度/风格,你最终一个难看的日历,缺少它是某些月份第一行。

此外setitng高度,以0不做任何事情,当你设置可见=假。如果您没有设置可见=假,只是把高度= 0它仍然无法正确渲染铬。所以,解决的办法是设置高度为 1

下面是我修改的方案。

在onrowrender

 保护无效Calendar1_DayRender(对象发件人,DayRenderEventArgs E){
    hideExtraWeek(发件人,E,(星期几)Calendar1.FirstDayOfWeek);
}

功能

 保护无效hideExtraWeek(对象发件人,DayRenderEventArgs E,DAYOFWEEK DW){
        如果(DW ==(星期几)7)DW =(星期几)0;当设置为默认// Firstdayofweek可返回7,但它是从零开始因此有效值为0〜6
        布尔blnBrowserDoesntSupportsEmptyRow = Request.Browser.Browser ==铬||
                                            Request.Browser.Browser ==野生动物园;        INT一周中的某天= Convert.ToInt16(e.Day.Date.DayOfWeek);
        INT补偿=一个dayOfWeek - Convert.ToInt16(DW);
        日期时间WeekStart = e.Day.Date.AddDays(-1 *补偿);
        周末的DateTime = WeekStart.AddDays(6);        //如果一周的开始和结束不具有相关性的当前月份
        如果(WeekStart.Month == WeekEnd.Month&放大器;&安培; e.Day.IsOtherMonth){
            e.Cell.Text =;
            e.Cell.Height = 1; //修复铬。可见=假留下一个空行,即使没有< TD> S在< TR>
            e.Cell.Visible = blnBrowserDoesntSupportsEmptyRow;
        }
    }

I am not sure why other people have not asked this before. But have you notice that the asp:Calendar shows an extra week at the end?

For example if the VisibleMonth is set to 2010-03-01 and FirstDayOfWeek to Sunday: It will show 6 weeks.

  1. Feb 28 to March 6
  2. March 7 to March 13
  3. March 14 to March 20
  4. March 21 to March 27
  5. March 28 to April 3
  6. April 4 to April 10

I was wondering why Microsoft shows the last Row which is entirely on April. I tried to search the net for a property but it does not seem to be existing.

The only solution that I could think of is to override the Pre_Render and check all individual date if they are still within the week of the VisibleDate. But of course that is an extreme checking since each rendering of the control shows it.

Here is my work around.

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;
    }
}

解决方案

very nice. Works with most browsers but is fugly with Chrome 11.0.696.71 And Safari for windows (havn't tested on mac)

For some months the calendar control displays the extra week at the start of the month. (when the 1st of the month is the first day of the week.)

When you set e.cell.Visible=false it doesn't render elements . So in chrome you end up with a row <tr></tr> . Chrome renders this as a blank row. And since i don't think there's a way to set the TR element height/style via the calendar control, you end up with an ugly looking calendar that's missing it's first row for certain months.

Also setitng height to 0 does nothing when you set Visible=false. If you don't set Visible=false and just put height =0 it still doesn't render correctly in chrome. So the solution is to set height to 1

Here's my modified solution.

the onrowrender

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e){
    hideExtraWeek(sender, e, (DayOfWeek)Calendar1.FirstDayOfWeek);
}

the function

    protected void hideExtraWeek(object sender, DayRenderEventArgs e, DayOfWeek dw){
        if (dw == (DayOfWeek)7) dw = (DayOfWeek)0; // FirstDayOfweek returns 7 when set to default, But it's zero based so valid values are 0 to 6
        Boolean blnBrowserDoesntSupportsEmptyRow= Request.Browser.Browser=="Chrome" ||
                                            Request.Browser.Browser=="Safari";

        int dayOfWeek = Convert.ToInt16(e.Day.Date.DayOfWeek);
        int compensate = dayOfWeek - Convert.ToInt16(dw);
        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==WeekEnd.Month && e.Day.IsOtherMonth){
            e.Cell.Text = "";
            e.Cell.Height = 1; // fix for chrome. Visible=false leaves a blank row even when there are no <td>s in the <tr>
            e.Cell.Visible = blnBrowserDoesntSupportsEmptyRow;
        }
    }

这篇关于如何删除上周日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆