Hi all, I need to highlight all the dates between the starting date and the ending date. I think I need to add the total numbers of days to the starting date.
This are my codes, how do I amend them inorder to add the total number of days and highlighting all the days?
void DayRender(Object sender, DayRenderEventArgs e)
{
Label15.Text = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
string user = (string)Session["UserID"];
string connStr1 = ConfigurationManager.ConnectionStrings["chinastudydbEntities"].ConnectionString;
MySqlConnection conn = new MySqlConnection(connStr1);
conn.Open();
MySqlCommand cmdUser = new MySqlCommand("SELECT StartDate, EndDate FROM attendance where UserID = '" + user + "' and StartDate = '" + Label15.Text + "'", conn);
MySqlCommand cmdDate = new MySqlCommand("SELECT StartDate from attendance where UserID = '" + user + "'", conn);
MySqlDataReader dr = cmdUser.ExecuteReader();
//using a while loop to read data from the reader
while (dr.Read())
{
DateTime dtStart = Convert.ToDateTime(dr["StartDate"].ToString());
DateTime dtEnd = Convert.ToDateTime(dr["EndDate"].ToString());
//for (DateTime dt = dtStart; dt < dtEnd; dt = dt.AddDays(1))
//{
// dt = dt.AddDays(1);
// e.Cell.Controls.Add(new LiteralControl("<br /><label style='color:black'>Leave</label>"));
// e.Cell.BackColor = System.Drawing.Color.Red;
//}
if (e.Day.Date.Date == dtStart.Date || e.Day.Date.Date == dtEnd.Date)
{
e.Cell.Controls.Add(new LiteralControl("<br /><label style='color:black'>Leave</label>"));
e.Cell.BackColor = System.Drawing.Color.Red;
Button1.Visible = false;
if (e.Day.Date.Date == DateTime.Now.Date)
{
e.Cell.ToolTip = "You already took a leave on this day!";
}
}
//for (DateTime dt2 = dtStart; dtEnd < dtStart; dt2 = dt2.AddDays(1))
//{
// Calendar1.SelectedDates.Add(dt2);
//}
}
dr.Close();
conn.Close();
}