sita k

sita k

  • NA
  • 43
  • 52k

Select a date from calendar control

Dec 5 2013 4:14 PM
Hello Everyone,

        I would like to display selected date from calendar control.First I am displaying the dates from the database in calendar control.It displays all the dates which are in database.Now the problem is when ever I select new date in the text box it always shows the date that I am displaying from the database.Is there anything I should do in coding.

        Below is my piece of code:
       

  protected void Page_Load(object sender, EventArgs e)

   {

       if (!Page.IsPostBack)

       {

            // Calls the Bind Method


                BindData();
        
} 
   }
    public void BindData()
    {
        // Define the select statement.
        string selectSQL;
       selectSQL = "SELECT adate fromappointment";
        OracleConnection con = new OracleConnection(connectionString);
        
OracleCommand cmd = new OracleCommand(selectSQL, con);
        OracleDataReader reader;  

      
try

        {
     
                con.Open();
                
reader = cmd.ExecuteReader();

            // Fill the controls.

           while(reader.Read())


           {
              Calendar1.SelectedDates.Add((DateTime)reader.GetOracleDate(0));
           }
        }
          catch
        {
            }
   }
        
protected
void Calendar1_SelectionChanged(object sender, EventArgs e)

    {
        BindData();
        string selects;
        lblDate.Text = Convert.ToDateTime(Calendar1.SelectedDate).ToString("dd-MMM-yyyy");    //This line Calendar1.SelectedDate always only 11-Nov-2013.
        selectSQL = "SELECT time from appointment where adate ='"+lblDate.Text+"'";    

        OracleConnection con = new OracleConnection(connectionString);

        OracleCommand cmd = new OracleCommand(selectSQL, con);

        OracleDataReader reader;       
        con.Open();

        reader = cmd.ExecuteReader();

        if (reader.Read())

            {           
                TextBox1.Text = reader["time"].ToString();
        }
       
        reader.Close();
    }


    What is the problem with this code?
                  







Answers (2)