Hi iammann,
I have created sample that full fill your requirement.
HTML
<div>
<asp:Calendar ID="Calendar1" OnDayRender=" Calendar1DayRender" runat="server"></asp:Calendar>
<br />
<b><span style="color: Red">Red</span></b><span> - Booked</span>
</div>
Code
protected DataSet dsDates;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Calendar1.VisibleDate = DateTime.Today;
}
GetDates();
}
//Get Dates from DataBase.
protected void GetDates()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[1] { new DataColumn("BookedDate", typeof(DateTime)) });
dt.Rows.Add(DateTime.Now);
dt.Rows.Add(DateTime.Now.AddDays(5));
dt.Rows.Add(DateTime.Now.AddDays(-5));
dt.Rows.Add(DateTime.Now.AddDays(30));
dt.Rows.Add(DateTime.Now.AddDays(-30));
dt.Rows.Add(DateTime.Now.AddDays(20));
DataSet ds = new DataSet();
ds.Tables.Add(dt);
dsDates = ds;
}
protected void Calendar1DayRender(object sender, DayRenderEventArgs e)
{
DateTime nextDate;
if (dsDates != null)
{
foreach (DataRow dr in dsDates.Tables[0].Rows)
{
nextDate = (DateTime)dr["BookedDate"];
if (nextDate.Date == e.Day.Date)
{
e.Day.IsSelectable = false;
e.Cell.BackColor = System.Drawing.Color.Red;
}
}
}
}
Screenshot