locked
Need help on the dates of the calendar! RRS feed

  • Question

  • User-415416754 posted

    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);
    conn.Open();
    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
    while (dr.Read())
    {
    DateTime dt = Convert.ToDateTime(dr["StartDate"].ToString());
    if (e.Day.Date.Day == dt.Day)
    {
    e.Cell.Controls.Add(new LiteralControl("<br />Leave"));
    }
    }
    dr.Close();

    conn.Close();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
    Panel1.Visible = false;
    Calendar1.DayRender += new DayRenderEventHandler(this.DayRender);
    }

    How do I solve this? Thank you!

    Tuesday, September 24, 2013 1:28 AM

Answers

  • User-1360095595 posted

    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)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 24, 2013 1:43 AM

All replies

  • User-1360095595 posted

    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)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 24, 2013 1:43 AM
  • User-415416754 posted

    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?

    Tuesday, September 24, 2013 2:49 AM