locked
Need help regarding the calendar! RRS feed

  • Question

  • User-415416754 posted

    Hi all, I have a calendar in my project. I want to make it like when the user chose a date that is before today's date, button 1 will disappear. I also want the button to disappear when there is already a booking inside. How do I do that? I have done some of my codes but it does not seem to be working. How do I solve those error?

    This is my codes :

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
    string now = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
    DateTime current = DateTime.Now;
    DateTime MyDateTime;
    MyDateTime = new DateTime();
    MyDateTime = DateTime.ParseExact(now, "yyyy-MM-dd",null);
    Label15.Text = Calendar1.SelectedDate.ToString("MM-dd-yyyy");
    TextBox1.Text = Label15.Text;
    string user = (string)Session["UserID"];
    Label12.Text = "";
    Label13.Text = "";
    Label14.Text = "";
    string mySQL;
    MySqlConnection connDate = new MySqlConnection(connStr);
    connDate.Open();
    mySQL = "Select StartDate, EndDate, Reason from attendance where UserID = '" + user + "' and StartDate = '" +now+"'";
    MySqlCommand cmdDate = new MySqlCommand(mySQL, connDate);
    MySqlDataReader dr = cmdDate.ExecuteReader();


    //using a while loop to read data from the reader
    while (dr.Read())
    {
    Label12.Text = dr["StartDate"].ToString().Trim();
    Label13.Text = dr["EndDate"].ToString().Trim();
    Label14.Text = dr["Reason"].ToString().Trim();
    string date = Label12.Text;

    if (MyDateTime < current)
    {
    Button1.Visible = false;
    }

    }
    dr.Close();
    Panel2.Visible = true;
    connDate.Close();

    }

    Wednesday, September 25, 2013 1:15 AM

Answers

  • User1970566204 posted

    hi,

     

     protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)       

      {      

               //u can check with all booked dates      

           if(e.Day.Date.Date== DateTime.Now.Date)  

              {               

     e.Day.IsSelectable = false;     

               e.Cell.ToolTip = "Cannot Book this date.";  

                }       

            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 25, 2013 2:13 AM