how to fill holiday and weekend in calender control with different colours?
for example for Weekend = black colour;
holiday = sky blue;
i tried below code but it only shows only single colour for both weekend and holiday.
if (dtholidays.Contains(e.Day.Date) || e.Day.IsWeekend)
{
e.Cell.BackColor = System.Drawing.Color.SkyBlue;
e.Cell.ForeColor = System.Drawing.Color.White;
}
Loading
Iftikar HussainPosted Aug 7, 2013, 4:41 AM
put the break point and check and also the check calendar render event
Regards,
Iftikar
Hardik PatelPosted Aug 7, 2013, 6:37 AM
it's done..
Iftikar HussainPosted Aug 7, 2013, 5:09 AM
e.Day.Date.ToShortDateString()
Regards,
Iftikar
Hardik PatelPosted Aug 7, 2013, 4:58 AM
if (HolidayList[e.Day.Date.ToShortDateString()] != null) //not working
{
e.Cell.ForeColor = System.Drawing.Color.Yellow;
Literal literal1 = new Literal();
literal1.Text = "
";
e.Cell.Controls.Add(literal1);
Label label1 = new Label();
label1.Text = (string)HolidayList[e.Day.Date.ToShortDateString()];
label1.Font.Size = new FontUnit(FontSize.Small);
e.Cell.Controls.Add(label1);
}
else if (e.Day.IsWeekend) // it's working
{
e.Cell.ForeColor = System.Drawing.Color.Red;
}
FillCalendar(e);
holiday list
["8/14/2013/"] ["janmastmi"]
.........
Hardik PatelPosted Aug 7, 2013, 4:37 AM
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Globalization;
using System.Threading;
using System.Collections;
public partial class User_Booking : System.Web.UI.Page
{
#region PageVariables
SQLDataAccessHelper sq = new SQLDataAccessHelper();
private DataSet ds;
private static int facilityid;
// List
Hashtable HolidayList;
#endregion
#region PageLoadEvents
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Username"] != null && Session["Username"].ToString() != "" && Session["Role"] != null && Session["Role"].ToString() != "")
{
if (Session["Username"] != null && Session["Username"].ToString() != "")
{
lblLoginStatus.Text = string.Format("{0} ", Session["Username"].ToString());
// dtholidays = GetPublicHolidays();
HolidayList = Getholiday();
}
else
{
lblLoginStatus.Text = "";
}
if (!IsPostBack)
{
//FillDDLFacility();
FillCHKFacility();
FetchEventsByFacility(0);
}
}
else
{
Response.Redirect("~/Login.aspx");
}
}
#endregion
#region PageLoadFunctions
//private List
//{
// List
// // populate from database or other sources
// list.Add(new DateTime(2013, 08, 15));
// list.Add(new DateTime(2013, 08, 18));
// list.Add(new DateTime(2013, 08, 20));
// list.Add(new DateTime(2013, 08, 28));
// list.Add(new DateTime(2013, 03, 14));
// list.Add(new DateTime(2013, 10, 02));
// //list.Add(new DateTime(2013, 10, 13));
// //list.Add(new DateTime(2013, 10, 16));
// //list.Add(new DateTime(2013, 11, 03));
// //list.Add(new DateTime(2013, 11, 04));
// //list.Add(new DateTime(2013, 06, 14));
// //list.Add(new DateTime(2013, 07, 02));
// //list.Add(new DateTime(2013, 07, 14));
// //list.Add(new DateTime(2013, 08, 02));
// //list.Add(new DateTime(2013, 08, 14));
// //list.Add(new DateTime(2013, 09, 02));
// //list.Add(new DateTime(2013, 09, 14));
// //list.Add(new DateTime(2013, 10, 02));
// //list.Add(new DateTime(2013, 10, 14));
// //list.Add(new DateTime(2013, 11, 02));
// //list.Add(new DateTime(2013, 11, 14));
// //list.Add(new DateTime(2013, 12, 02));
// //list.Add(new DateTime(2013, 12, 14));
// return list;
//}
private Hashtable Getholiday()
{
Hashtable holiday = new Hashtable();
holiday["1/1/2013"] = "New Year";
holiday["1/5/2013"] = "Guru Govind Singh Jayanti";
holiday["1/8/2013"] = "Muharam (Al Hijra)";
holiday["1/14/2013"] = "Pongal";
holiday["1/26/2013"] = "Republic Day";
holiday["2/23/2013"] = "Maha Shivaratri";
holiday["3/10/2013"] = "Milad un Nabi (Birthday of the Prophet";
holiday["3/21/2013"] = "Holi";
holiday["3/21/2013"] = "Telugu New Year";
holiday["4/3/2013"] = "Ram Navmi";
holiday["4/7/2013"] = "Mahavir Jayanti";
holiday["4/10/2013"] = "Good Friday";
holiday["4/12/2013"] = "Easter";
holiday["4/14/2013"] = "Tamil New Year and Dr Ambedkar Birth Day";
holiday["5/1/2013"] = "May Day";
holiday["5/9/2013"] = "Buddha Jayanti and Buddha Purnima";
holiday["6/24/2013"] = "Rath yatra";
holiday["8/13/2013"] = "Krishna Jayanthi";
holiday["8/14/2013"] = "Janmashtami";
holiday["8/15/2013"] = "Independence Day";
holiday["8/19/2013"] = "Parsi New Year";
holiday["8/23/2013"] = "Vinayaka Chaturthi";
holiday["9/2/2013"] = "Onam";
holiday["9/5/2013"] = "Teachers Day";
holiday["9/21/2013"] = "Ramzan";
holiday["9/27/2013"] = "Ayutha Pooja";
holiday["9/28/2013"] = "Vijaya Dasami (Dusherra)";
holiday["10/2/2013"] = "Gandhi Jayanti";
holiday["10/17/2013"] = "Diwali & Govardhan Puja";
holiday["10/19/2013"] = "Bhaidooj";
holiday["11/2/2013"] = "Guru Nanak Jayanti";
holiday["11/14/2013"] = "Children's Day";
holiday["11/28/2013"] = "Bakrid";
holiday["12/25/2013"] = "Christmas";
holiday["12/28/2013"] = "Muharram";
return holiday;
}
private void FillCHKFacility()
{
try
{
sq = new SQLDataAccessHelper();
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@facilityid", SqlDbType.Int);
param[0].Value = DBNull.Value;
ds = new DataSet();
ds = sq.ExecuteDataSet("usp_FillFacility", param);
if ((ds != null) && (ds.Tables.Count != 0) && (ds.Tables[0].Rows.Count != 0))
{
rblFacility.Items.Clear();
rblFacility.DataSource = ds;
rblFacility.DataTextField = "FacilityName";
rblFacility.DataValueField = "FacilityId";
rblFacility.DataBind();
rblFacility.Items.Insert(0, "All");
rblFacility.SelectedIndex = 0;
}
else
{
rblFacility.Items.Clear();
rblFacility.DataSource = null;
rblFacility.DataBind();
rblFacility.Items.Insert(0, "N/A");
}
}
catch { }
finally { }
}
private void FetchEventsByFacility(int facilityid)
{
try
{
string query = "";
sq = new SQLDataAccessHelper();
ds = new DataSet();
if (facilityid == 0)
{
query += "Select * from FUN_EventsByFacility(null)";
}
else
{
query += "Select * from FUN_EventsByFacility(" + facilityid + ")";
}
ds = sq.ExecuteCommandText(query);
if ((ds != null) && (ds.Tables.Count != 0) && (ds.Tables[0].Rows.Count != 0))
{
ViewState["EventsByFacility"] = ds.Tables[0];
}
else
{
ViewState["EventsByFacility"] = null;
}
}
catch { }
}
#endregion
#region ControlEvents
protected void eventCalendar_DayRender(object sender, DayRenderEventArgs e)
{
if (HolidayList[e.Day.Date.ToShortDateString()] != null)
{
Literal literal1 = new Literal();
literal1.Text = "
";
e.Cell.Controls.Add(literal1);
Label label1 = new Label();
label1.Text = (string)HolidayList[e.Day.Date.ToShortDateString()];
label1.Font.Size = new FontUnit(FontSize.Small);
e.Cell.Controls.Add(label1);
}
else if (e.Day.IsWeekend)
{
e.Cell.ForeColor = System.Drawing.Color.Red;
}
FillCalendar(e);
}
protected void eventCalendar_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
LabelAction.Text = "Month changed to :" + e.NewDate.ToShortDateString();
}
protected void eventCalendar_SelectionChanged(object sender, EventArgs e)
{
LabelAction.Text = "Date changed to :" + eventCalendar.SelectedDate.ToShortDateString();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (txtFromDate.Text != "" && txtToDate.Text != "")
{
DateTime from, to;
from = Convert.ToDateTime(txtFromDate.Text).Date;
to = Convert.ToDateTime(txtToDate.Text).Date;
Response.Redirect("ViewBooking.aspx?From=" + from + "&To=" + to + "");
}
}
protected void rblFacility_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
facilityid = 0;
for (int i = 0; i < rblFacility.Items.Count; i++)
{
if (rblFacility.Items[i].Selected == true)
{
if (rblFacility.Items[i].Text == "All")
{
facilityid = 0;
}
else
{
facilityid = Convert.ToInt32(rblFacility.Items[i].Value);
}
}
}
FetchEventsByFacility(facilityid);
}
catch { }
}
#endregion
#region HelperFunctions
private void SetCalendarCustomPrevNext()
{
DateTime nextMonth = eventCalendar.VisibleDate.AddMonths(1);
string nextmonthText = "";
nextmonthText = "
nextmonthText += "
nextmonthText += "
nextmonthText += "" + nextMonth.ToString("MMM") + "";
nextmonthText += "
nextmonthText += "
nextmonthText += "
eventCalendar.NextMonthText = nextmonthText;
DateTime prevMonth = eventCalendar.VisibleDate.AddMonths(-1);
string prevmonthText = "";
prevmonthText = "
prevmonthText += "
prevmonthText += "
prevmonthText += "" + prevMonth.ToString("MMM") + "";
prevmonthText += "
prevmonthText += "
prevmonthText += "
eventCalendar.PrevMonthText = prevmonthText;
}
protected override void InitializeCulture()
{
CultureInfo CI = new CultureInfo("en-US");
CI.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy";
Thread.CurrentThread.CurrentCulture = CI;
Thread.CurrentThread.CurrentUICulture = CI;
base.InitializeCulture();
}
private void FillCalendar(DayRenderEventArgs evt)
{
LinkButton lb = new LinkButton();
//if (dtholidays.Contains(e.Day.Date))
//{
// //e.Cell.BackColor = System.Drawing.Color.LightBlue;
// //e.Cell.ForeColor = System.Drawing.Color.White;
//}
//else if (e.Day.IsWeekend)
//{
// //e.Cell.BackColor = System.Drawing.Color.LightPink;
// //e.Cell.ForeColor = System.Drawing.Color.White;
//}
//im.ImageUrl =
lb.Text = "Add Event";
lb.ID = "lb" + evt.Day.Date.Day.ToString() + evt.Day.Date.Month;
lb.Attributes.Add("style", "display:none;cursor:pointer;");
lb.Attributes.Add("onclick", "javascript:window.location='BookEvent.aspx?From=" + evt.Day.Date.ToString("dd-MM-yyyy") + "&To=" + evt.Day.Date.ToString("dd-MM-yyyy") + "';");
evt.Cell.Attributes.Add("onmouseover", "showlink('" + lb.ClientID + "')");
evt.Cell.Attributes.Add("onmouseout", "hidelink('" + lb.ClientID + "')");
evt.Cell.Controls.Add(lb);
DataTable dt = (DataTable)ViewState["EventsByFacility"];
if (dt != null)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
string bookingdate = Convert.ToDateTime(dt.Rows[i]["BookingDate"]).Date.ToString("dd-MM-yyyy");
if (evt.Day.Date.ToString("dd-MM-yyyy") == bookingdate)
{
evt.Cell.Attributes.Clear();
string trainingtopic = dt.Rows[i]["TrainingTopic"].ToString();
string UserName = dt.Rows[i]["UserName"].ToString();
string strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
string strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/");
strUrl += HttpContext.Current.Request.ApplicationPath.ToString().Replace("/", "");
string img = strUrl + "/Admin" + dt.Rows[i]["img"].ToString();
string facilityname = dt.Rows[i]["FacilityName"].ToString();
string trainingsession = dt.Rows[i]["TrainingSession"].ToString();
string approved = dt.Rows[i]["IsAdminApproved"].ToString();
string cssclass = "";
if (approved == "True")
{
cssclass = "eventconfirmed";
}
else
{
cssclass = "eventpending";
}
if (trainingtopic != "")
{
LiteralControl lt = new LiteralControl();
Image imn = new Image();
lt.Text = "
"; ";
";lt.Text += "" + facilityname + " | " + UserName + "|
lt.Text += " | ";
lt.Text += "View";
lt.Text += " | ";
lt.Text += "New Event";
lt.Text += "
//evt.Cell.Controls.Add(new LiteralControl("
" + trainingtopic + " | " + facilityname + " | " + trainingsession + "
"));//evt.Cell.Controls.Add(GenerateTable(trainingtopic, facilityname, trainingsession,cssclass));
evt.Cell.Controls.Add(lt);
// evt.Cell.Controls.Add(imn);
evt.Cell.CssClass = "content";
}
}
}
}
}
#endregion
protected void Logout(object sender, EventArgs e)
{
Session["Username"] = null;
Session["UserId"] = null;
Session["Role"] = null;
this.Session.Clear();
this.Session.Abandon();
Response.Redirect("~/Login.aspx");
}
}
Hardik PatelPosted Aug 7, 2013, 4:36 AM
"; e.Cell.Controls.Add(literal1); Label label1 = new Label(); label1.Text = (string)HolidayList[e.Day.Date.ToShortDateString()]; label1.Font.Size = new FontUnit(FontSize.Small); e.Cell.Controls.Add(label1); } else if (e.Day.IsWeekend) { e.Cell.ForeColor = System.Drawing.Color.Red; } FillCalendar(e); } protected void eventCalendar_VisibleMonthChanged(object sender, MonthChangedEventArgs e) { LabelAction.Text = "Month changed to :" + e.NewDate.ToShortDateString(); } protected void eventCalendar_SelectionChanged(object sender, EventArgs e) { LabelAction.Text = "Date changed to :" + eventCalendar.SelectedDate.ToShortDateString(); } protected void btnSubmit_Click(object sender, EventArgs e) { if (txtFromDate.Text != "" && txtToDate.Text != "") { DateTime from, to; from = Convert.ToDateTime(txtFromDate.Text).Date; to = Convert.ToDateTime(txtToDate.Text).Date; Response.Redirect("ViewBooking.aspx?From=" + from + "&To=" + to + ""); } } protected void rblFacility_SelectedIndexChanged(object sender, EventArgs e) { try { facilityid = 0; for (int i = 0; i < rblFacility.Items.Count; i++) { if (rblFacility.Items[i].Selected == true) { if (rblFacility.Items[i].Text == "All") { facilityid = 0; } else { facilityid = Convert.ToInt32(rblFacility.Items[i].Value); } } } FetchEventsByFacility(facilityid); } catch { } } #endregion #region HelperFunctions private void SetCalendarCustomPrevNext() { DateTime nextMonth = eventCalendar.VisibleDate.AddMonths(1); string nextmonthText = ""; nextmonthText = "
"; lt.Text += "" + facilityname + " | " + UserName + "| ";
lt.Text += " | ";
lt.Text += "View";
lt.Text += " | ";
lt.Text += "New Event";
lt.Text += "
"; //evt.Cell.Controls.Add(new LiteralControl("" + trainingtopic + " | " + facilityname + " | " + trainingsession + "
")); //evt.Cell.Controls.Add(GenerateTable(trainingtopic, facilityname, trainingsession,cssclass)); evt.Cell.Controls.Add(lt); // evt.Cell.Controls.Add(imn); evt.Cell.CssClass = "content"; } } } } } #endregion protected void Logout(object sender, EventArgs e) { Session["Username"] = null; Session["UserId"] = null; Session["Role"] = null; this.Session.Clear(); this.Session.Abandon(); Response.Redirect("~/Login.aspx"); } }Iftikar HussainPosted Aug 7, 2013, 3:20 AM
Regards,
Iftikar
Hardik PatelPosted Aug 7, 2013, 3:03 AM
Iftikar HussainPosted Aug 7, 2013, 2:57 AM
Regards,
Iftikar
Hardik PatelPosted Aug 7, 2013, 2:51 AM
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
Hashtable HolidayList;
protected void Page_Load(object sender, EventArgs e)
{
HolidayList = Getholiday();
Calendar1.Caption = "Calender - Author: Puran Singh Mehra";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Calendar1.ShowGridLines = true;
Calendar1.DayStyle.Height = new Unit(50);
Calendar1.DayStyle.Width = new Unit(150);
Calendar1.DayStyle.HorizontalAlign = HorizontalAlign.Center;
Calendar1.DayStyle.VerticalAlign = VerticalAlign.Middle;
Calendar1.OtherMonthDayStyle.BackColor = System.Drawing.Color.AliceBlue;
}
private Hashtable Getholiday()
{
Hashtable holiday = new Hashtable();
holiday["1/1/2009"] = "New Year";
holiday["1/5/2009"] = "Guru Govind Singh Jayanti";
holiday["1/8/2009"] = "Muharam (Al Hijra)";
holiday["1/14/2009"] = "Pongal";
holiday["1/26/2009"] = "Republic Day";
holiday["2/23/2009"] = "Maha Shivaratri";
holiday["3/10/2009"] = "Milad un Nabi (Birthday of the Prophet";
holiday["3/21/2009"] = "Holi";
holiday["3/21/2009"] = "Telugu New Year";
holiday["4/3/2009"] = "Ram Navmi";
holiday["4/7/2009"] = "Mahavir Jayanti";
holiday["4/10/2009"] = "Good Friday";
holiday["4/12/2009"] = "Easter";
holiday["4/14/2009"] = "Tamil New Year and Dr Ambedkar Birth Day";
holiday["5/1/2009"] = "May Day";
holiday["5/9/2009"] = "Buddha Jayanti and Buddha Purnima";
holiday["6/24/2009"] = "Rath yatra";
holiday["8/13/2009"] = "Krishna Jayanthi";
holiday["8/14/2009"] = "Janmashtami";
holiday["8/15/2009"] = "Independence Day";
holiday["8/19/2009"] = "Parsi New Year";
holiday["8/23/2009"] = "Vinayaka Chaturthi";
holiday["9/2/2009"] = "Onam";
holiday["9/5/2009"] = "Teachers Day";
holiday["9/21/2009"] = "Ramzan";
holiday["9/27/2009"] = "Ayutha Pooja";
holiday["9/28/2009"] = "Vijaya Dasami (Dusherra)";
holiday["10/2/2009"] = "Gandhi Jayanti";
holiday["10/17/2009"] = "Diwali & Govardhan Puja";
holiday["10/19/2009"] = "Bhaidooj";
holiday["11/2/2009"] = "Guru Nanak Jayanti";
holiday["11/14/2009"] = "Children's Day";
holiday["11/28/2009"] = "Bakrid";
holiday["12/25/2009"] = "Christmas";
holiday["12/28/2009"] = "Muharram";
return holiday;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
LabelAction.Text = "Date changed to :" + Calendar1.SelectedDate.ToShortDateString();
}
protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
LabelAction.Text = "Month changed to :" + e.NewDate.ToShortDateString();
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (HolidayList[e.Day.Date.ToShortDateString()] != null)
{
Literal literal1 = new Literal();
literal1.Text = "
";
e.Cell.Controls.Add(literal1);
Label label1 = new Label();
label1.Text = (string)HolidayList[e.Day.Date.ToShortDateString()];
label1.Font.Size = new FontUnit(FontSize.Small);
e.Cell.Controls.Add(label1);
}
}
}
Iftikar HussainPosted Aug 7, 2013, 1:47 AM
http://www.c-sharpcorner.com/uploadfile/puranindia/calendar-control-in-Asp-Net/
Regards,
Iftikar
Hardik PatelPosted Aug 7, 2013, 1:38 AM
Iftikar HussainPosted Aug 7, 2013, 1:36 AM
Regards,
Iftikar
Hardik PatelPosted Aug 7, 2013, 1:34 AM
private List
{
List
//populate from database or other sources
list.Add(new DateTime(2013, 08, 15));
list.Add(new DateTime(2013, 08, 18));
return list;
}
but i want holiday list with description
15/08/2013 - independence day and also want to dispaly it in calender cell.
Hardik PatelPosted Aug 7, 2013, 1:24 AM
Iftikar HussainPosted Aug 7, 2013, 12:46 AM
Regards,
Iftikar
Hardik PatelPosted Aug 7, 2013, 12:38 AM
Iftikar HussainPosted Aug 7, 2013, 12:33 AM
Try like this
Regards,
Iftikar