Hey guys, I want to color the calendar cells according to my database date. I have already did some of the codes for this. However, it only colours one of the date of the user. For example, the user has 3 dates booked in the database. 1-3, 23,26 and 28-31(Dates booked by the user that are stored in the database). This particular user has 3 dates booked. However, now I am only to show 1 of those days instead of all 3. How do I modify the code to show all the dates that the user has booked?
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 + "'", 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());
string year = Calendar1.SelectedDate.Year.ToString();
//if you do not select any date, it will retrun 1
if (year == "1")
{
Calendar1.SelectedDate = Calendar1.TodaysDate;
Calendar1.SelectedDates.SelectRange(dtStart.Date, dtEnd.Date);
Calendar1.SelectedDayStyle.BackColor = System.Drawing.Color.Red;
Button1.Visible = false;
}
}
dr.Close();
conn.Close();
}
How do I modify the codes above to what I want to achieve? Please help! Thank you!