Telerik MVC DatePicker禁用星期几

时间:2012-07-07 05:39:11

标签: asp.net-mvc-3 telerik telerik-datepicker

有没有办法让DatePicker允许用户仅从星期日开始的一周开始的弹出日期中选择星期日/星期六。星期六结束了吗?

我有2个DatePickers作为范围(来自& to),验证是允许用户只选择from框中的Sunday和to to box中的Saturday。

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

也许你可以为所有星期几的链接添加一个jquery事件处理程序(周末天在td上有一个周末类)并防止默认行为,所以每当你点击它们时都不做任何事情。此外,您可能希望更改工作日值的样式,以便用户不会因为点击而没有获得所需的效果而烦恼

答案 1 :(得分:0)

在aspx中添加以下代码

   <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="DefaultCS" %>

 <%@ Register TagPrefix="radcln" Namespace="Telerik.WebControls" Assembly="RadCalendar.Net2" %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

        <script type="text/javascript">
        function OnDayRender(calendarInstance, args)
        {   
            var jsDate = new Date(args.Date[0], args.Date[1] - 1, args.Date[2]);
            if (jsDate.getDay() != 0)//(jsDate.getDay()!=6) for Saturday 
            {
                var otherMonthCssClass = "otherMonth_" + calendarInstance.Skin;    
                args.Cell.className = otherMonthCssClass; 
                args.Cell.innerHTML = "<span>" + args.Date[2] + "</span>";
                args.Cell.DayId = "";
            }  
        }
        </script>

        <radcln:RadDatePicker ID="RadDatePicker1" runat="server">
            <Calendar OnDayRender="Calendar_OnDayRender">
                <ClientEvents OnDayRender="OnDayRender" />
            </Calendar>
        </radcln:RadDatePicker>        

</div>
</form>

和cs文件

using System;
using System.Web.UI.WebControls;
using Telerik.WebControls;
using Telerik.WebControls.Base.Calendar.Enumerations;

public partial class DefaultCS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
    {
        RadDatePicker1.Calendar.SpecialDays.Clear();
    }
}

protected void Calendar_OnDayRender(object sender, Telerik.WebControls.Base.Calendar.Events.DayRenderEventArgs e)
{
    if (e.Day.Date.DayOfWeek != DayOfWeek.Sunday) //(e.Day.Date.DayOfWeek != DayOfWeek.Saturday) for Saturday
    {
        string calendarSkin = RadDatePicker1.Calendar.Skin != "" ? RadDatePicker1.Calendar.Skin : "Default";
        string otherMonthCssClass = String.Format("otherMonth_{0}", calendarSkin);
        e.Cell.Text = "";
        e.Cell.CssClass = otherMonthCssClass; //set new CssClass for the disabled calendar day cells (e.g. look like other month days here)
        Label label = new Label();
        label.Text = e.Day.Date.Day.ToString();
        e.Cell.Controls.Add(label);
        RadCalendarDay calendarDay = new RadCalendarDay();
        calendarDay.Date = e.Day.Date;
        calendarDay.IsSelectable = false;
        calendarDay.ItemStyle.CssClass = otherMonthCssClass;
        RadDatePicker1.Calendar.SpecialDays.Add(calendarDay);
    }

}

}