Last post Sep 24, 2013 02:49 AM by HaydenHH
Sep 24, 2013 01:28 AM|HaydenHH|LINK
Hi guys, I want to make a calendar with the text leave under the date when the user has choosen the date. It is working. However,for example today is 24-9-13, the user has already chosen the date thus the date 24 will have the word leave below. This is correct.
However, when I change the calendar to the next month, the date 24 also has the word leave which is wrong. How do I solve this?
This is my code :
void DayRender(Object sender, DayRenderEventArgs e)
string user = (string)Session["UserID"];
string connStr1 = ConfigurationManager.ConnectionStrings["chinastudydbEntities"].ConnectionString;
MySqlConnection conn = new MySqlConnection(connStr1);
MySqlCommand cmdUser = new MySqlCommand("SELECT * FROM attendance where UserID = '"+user+"'", conn);
MySqlDataReader dr = cmdUser.ExecuteReader();
//using a while loop to read data from the reader
DateTime dt = Convert.ToDateTime(dr["StartDate"].ToString());
if (e.Day.Date.Day == dt.Day)
e.Cell.Controls.Add(new LiteralControl("<br />Leave"));
protected void Page_Load(object sender, EventArgs e)
Panel1.Visible = false;
Calendar1.DayRender += new DayRenderEventHandler(this.DayRender);
How do I solve this? Thank you!
Sep 24, 2013 01:43 AM|MetalAsp.Net|LINK
Your problem is here: if (e.Day.Date.Day == dt.Day); this is only taking the Day of the month into consideration. Simply compare the whole Date instead of Day: if (e.Day.Date.Date == dt.Date)
Sep 24, 2013 02:49 AM|HaydenHH|LINK
Hi sorry to bother you. If I want to make all the dates from the starting date to the ending date all with the word leave. How do I do that?
For example, 24th - 30th.
How do I modify the codes to make this happen?