- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有时在显示日历时,有必要防止周末日期和日期标题中的周末名称显示,有没有办法使用 ASP.NET Calendar control 来做到这一点。 ?
最佳答案
由于提供了控件,因此在不覆盖控件的情况下无法执行此操作。这样做的一种方法是覆盖 OnDayRender和 Render在将信息发送回客户端之前从输出中删除信息的方法。
以下是控件在呈现时的外观的屏幕截图:
下面是一个基本的控件覆盖,演示了从控件中删除周末列。
/*------------------------------------------------------------------------------
* Author - Rob (http://stackoverflow.com/users/1185/rob)
* -----------------------------------------------------------------------------
* Notes
* - This might not be the best way of doing things, so you should test it
* before using it in production code.
* - This control was inspired by Mike Ellison's article on The Code Project
* found here: http://www.codeproject.com/aspnet/MellDataCalendar.asp
* ---------------------------------------------------------------------------*/
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Xml;
namespace DataControls
{
/// <summary>
/// Example of a ASP.NET Calendar control that has been overriden to force
/// the weekend columns to be hidden on demand.
/// </summary>
public class DataCalendar : Calendar
{
private bool _hideWeekend;
private int _saturday;
private int _sunday;
/// <summary>Constructor</summary>
public DataCalendar()
: base()
{
// Default to showing the weekend
this._hideWeekend = false;
// Set the default values for Saturday and Sunday
this.Saturday = 6;
this.Sunday = 0;
}
/// <summary>
/// Indicate if the weekend days should be shown or not, set to true
/// if the weekend should be hidden, false otherwise. This field
/// defaults to false.
/// </summary>
public bool HideWeekend
{
get { return this._hideWeekend; }
set { this._hideWeekend = value; }
}
/// <summary>
/// Override the default index for Saturdays.
/// </summary>
/// <remarks>This option is provided for internationalization options.</remarks>
public int Saturday
{
get { return this._saturday; }
set { this._saturday = value; }
}
/// <summary>
/// Override the default index for Sundays.
/// </summary>
/// <remarks>This option is provided for internationalization options.</remarks>
public int Sunday
{
get { return this._sunday; }
set { this._sunday = value; }
}
/// <summary>
/// Render the day on the calendar with the information provided.
/// </summary>
/// <param name="cell">The cell in the table.</param>
/// <param name="day">The calendar day information</param>
protected override void OnDayRender(TableCell cell, CalendarDay day)
{
// If this is a weekend day and they should be hidden, remove
// them from the output
if (day.IsWeekend && this._hideWeekend)
{
day = null;
cell.Visible = false;
cell.Text = string.Empty;
}
// Call the base render method too
base.OnDayRender(cell, day);
}
/// <summary>
/// Render the calendar to the HTML stream provided.
/// </summary>
/// <param name="html">The output control stream to write to.</param>
protected override void Render(HtmlTextWriter html)
{
// Setup a new HtmlTextWriter that the base class will use to render
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter calendar = new HtmlTextWriter(sw);
// Call the base Calendar's Render method allowing OnDayRender()
// to be executed.
base.Render(calendar);
// Check to see if we need to remove the weekends from the header,
// if we do, then remove the fields and use the new verison for
// the output. Otherwise, just use what was previously generated.
if (this._hideWeekend && this.ShowDayHeader)
{
// Load the XHTML to a XML document for processing
XmlDocument xml = new XmlDocument();
xml.Load(new StringReader(sw.ToString()));
// The Calendar control renders as a table, so navigate to the
// second TR which has the day headers.
XmlElement root = xml.DocumentElement;
XmlNode oldNode = root.SelectNodes("/table/tr")[1];
XmlNode sundayNode = oldNode.ChildNodes[this.Sunday];
XmlNode saturdayNode = oldNode.ChildNodes[this.Saturday];
XmlNode newNode = oldNode;
newNode.RemoveChild(sundayNode);
newNode.RemoveChild(saturdayNode);
root.ReplaceChild(oldNode, newNode);
// Replace the buffer
html.WriteLine(root.OuterXml);
}
else
{
html.WriteLine(sw.ToString());
}
}
}
}
关于asp.net - 使用 ASP.NET 日历控件时如何隐藏周末?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/554111/
有人可以帮我解决这个问题吗?当填写周五、周六或周日时,需要返回"is",而在所有其他情况下,则需要返回“否”。每次它都以“JA”结尾...... 代码: // Nieuwe Array aan
我知道,标题并不具体,但我对 DatePicker 有疑问。我尝试禁用国庆节、周末和今天之后的 48 小时。目前我这样做了: 隐藏今天 + 48 小时,我使用 minDate: 3 隐藏周末 隐藏国庆
我必须计算以下两个日期之间的周末计数和假期计数。 var startDate = new Date("01/02/2014"); var endDate = new Date("02/
我正在尝试编写一个脚本来实现以下目的: 我需要根据一天中的时间和星期几将我页面上某个元素的颜色从绿色更改为红色。因此,例如,在星期六我需要一个不同于星期一的时间窗口。 我正在努力寻找有用的东西。我找到
给定 postgres 中的 2 个时间戳,你如何在不计算整个星期六和星期日的情况下计算时差? 或 如何计算给定时间间隔内的周六和周日的数量? 最佳答案 以下函数返回两个日期之间的完整周末天数。由于您
我无法在没有周末的情况下呈现日期时间图表。怎么做到的? 这是示例代码 ( http://jsfiddle.net/LLExL/1720/ ): $('#container').highcharts({
ax.plot_date((dates, dates), (highs, lows), '-') 我目前正在使用此命令通过 Matplotlib 绘制财务高点和低点.效果很好,但如何删除 x 轴上因没
从今天早上开始,我无法使用原始 HTTP 协议(protocol)在用户对象上设置 orgUnitPath。 PATCH /admin/directory/v1/users/testuser_1440
我有这些 Dag DAG_A(每天运行)、DAG_B(周一至周五运行)和 DAG_C(周六和周日运行),其中 DAG_A 依赖于 DAG_B 和 DAG_C。我尝试使用 External Task S
我正在使用 JQuery UI Datepicker Disbale Next Day After 12pm 中的代码禁用周末、公共(public)假期和第二天(如果在上午 10 点之后选择),但我不
我是一名优秀的程序员,十分优秀!