1

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

我可以使用以下脚本在 asp 日历控件中阻止日期。图像示例.. 在此处输入图像描述 我正在从数据库中读取预订日期并以不同颜色突出显示这些日期。这在 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>
4

0 回答 0