asp.net – 如何删除日历的最后一周
我不确定为什么其他人之前没有问过这个问题.但是你注意到asp:Calendar最后会显示额外的一周吗?
例如,如果VisibleMonth设置为2010-03-01,FirstDayOfWeek设置为Sunday: > 2月28日至3月6日 我想知道为什么微软显示完全在四月份的最后一行.我试图在网上搜索一个房产,但它似乎并不存在. 我能想到的唯一解决方案是覆盖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; } } 解决方法
非常好.与大多数浏览器一起使用,但是对于Chrome 11.0.696.71和Safari for Windows(在Mac上没有测试过)很难看
在某些月份,日历控件会在月初显示额外的一周. (当月的第一天是一周的第一天.) 设置e.cell.Visible = false时,它不会渲染元素.所以在chrome中你得到一行< tr>< / tr> . Chrome将其渲染为空白行.而且由于我认为没有办法通过日历控件设置TR元素的高度/样式,你最终会看到一个难看的日历,它缺少它在某些月份的第一行. 设置Visible = false时,将高度设置为0也不起作用.如果您没有设置Visible = false并且只是将height设置为0,则它??仍然无法在chrome中正确呈现.所以解决方法是将高度设置为1 这是我修改过的解决方案. onrowrender protected void Calendar1_DayRender(object sender,DayRenderEventArgs e){ hideExtraWeek(sender,e,(DayOfWeek)Calendar1.FirstDayOfWeek); } 功能 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; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp-classic – 经典asp – 更好地做很多响应.写或使用<%
- 什么时候最好在ASP.NET中使用静态函数?
- ASP.NET MVC和WCF
- asp.net-mvc – ASP.NET MVC – 从URL中删除控制器名称
- asp.net-core – 带有JSONP的ASP.NET Core MVC
- C#--图片上传(PC端和APP)保存及 跨域上传说明
- asp.net-mvc – ASP.NET MVC领域:它们对大型应用程序很重要
- asp.net-mvc-3 – ASP.NET MVC 3 _Layout.cshtml控制器
- asp.net – DDR Treeview菜单显示选定的根及其子节点
- .net – 比较文本并获得差异