ajax日历控件的Ajax Calendar Day呈现事件或如何在ajax日历中阻止某些日期

时间:2012-05-30 05:11:52

标签: c# asp.net calendar

在ajax日历控件上禁用日期。

我可以使用以下脚本阻止asp日历控件中的日期。 图像示例.. enter image description here 我正在从数据库&读取预订日期突出显示不同颜色的日期。这在asp.net日历中运行良好,但我想在ajax日历控件中实现它。

protected void CalendarDayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
    // If the month is CurrentMonth
    if (!e.Day.IsOtherMonth)
    {
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            if ((dr["BookingDate"].ToString() != DBNull.Value.ToString()))
            {
                DateTime dtEvent = (DateTime)dr["BookingDate"];
                if (dtEvent.Equals(e.Day.Date))
                {
                    e.Cell.BackColor = Color.PaleVioletRed;
                   // e.Day.IsSelectable = False;

                }
            }
        }
    }
    //If the month is not CurrentMonth then hide the Dates
    else
    {
        e.Cell.Text = "";
    }
}

我需要对Ajax日历控件执行相同的操作

但是当我在Ajax prerender事件

下放置相同的代码时,我无法做到这一点
    protected void AjaxCalendar_PreRender(object sender, EventArgs e)
    {
        //startdate= enddate="2012-06-25"
        DateTime startDate = Helper.GetUAEDateTime();
        DateTime endDate = DateTime.Now.AddDays(10);

        AjaxCalendar.StartDate = startDate;
        AjaxCalendar.EndDate = endDate;     
//Here i nee code to block date if it is booked in the database 
    }

我查找了一些示例,以便我可以从代码中执行此操作,但到目前为止,我无法使用Ajax日历控件。

我正在阅读数据库中的值&阻止已预订的日期。

我很感激这方面的帮助

HTML代码供参考

<div>

        <asp:TextBox ID="TextBox1" runat="server" Height="27px" Width="279px"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" OnDayRender="CalendarDayRender" 
            BorderColor="#3366CC" BorderWidth="1px" Font-Names="Verdana" Font-Size="8pt" 
            ForeColor="#003399" Height="200px" Width="220px" CellPadding="1" 
            DayNameFormat="Shortest"  >
            <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
            <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
            <OtherMonthDayStyle ForeColor="#999999" />
            <SelectedDayStyle BackColor="#009999" ForeColor="#CCFF99" Font-Bold="True" />
            <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
            <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" 
                Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
            <TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
            <WeekendDayStyle BackColor="#CCCCFF" />
        </asp:Calendar>

        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:CalendarExtender ID="AjaxCalendar" runat="server"  
             TargetControlID="TextBox2" Format="yyyy-MM-dd" 
             onprerender="AjaxCalendar_PreRender" >
        </asp:CalendarExtender>
    </div>

0 个答案:

没有答案