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?
sita kPosted Dec 6, 2013, 1:00 AM
Thanks for your response.If i don't bind the data then when ever i select new date then the dates from database are not highlighted. Is there anything that i can do that i can select a new date and even display my database dates?
Jaganathan BantheswaranPosted Dec 6, 2013, 12:26 AM
Why do you want to re-bind the calender everytime when the date is selected?
see in the selectionChanged event,
BindData() - is called everytime..