C# Ajax日历控件的Ajax日历日呈现事件或如何在Ajax日历中阻止某些日期
禁用ajax日历控件上的日期C# Ajax日历控件的Ajax日历日呈现事件或如何在Ajax日历中阻止某些日期,c#,asp.net,calendar,C#,Asp.net,Calendar,禁用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) {
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 = "";
}
}
我可以用下面的脚本阻止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日历控件完成
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 = "";
}
}
我正在从数据库中读取值&阻塞已经预订的日期
我非常感谢你在这方面的帮助
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>