huby Posted July 6, 2004 Posted July 6, 2004 hello everyone! i am trying to use a calendar control. basic function, really. i want to click on a date, query a database for events for which the date is the same, and then display the events. my problem is that i can't find the way to extract the date from the calendar control to pass it as a parameter to my sqlcommand object. i set a breakpoint on the SelectionChanged sub, but when i run it, my code never actually stops at that event. ok, here's some code : private DateTime _dt; private void Page_Load(object sender, System.EventArgs e) { //on first execution, we just use today's date if (!this.IsPostBack) { _dt = DateTime.Now; } LoadEvents(); } private void LoadEvents() { string strSQL = "Select * from Events WHERE eventStartDate = @date order by eventStartDate asc"; SqlConnection conn = new SqlConnection(myConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand(strSQL,conn); SqlParameter prm = new SqlParameter(); prm.SqlDbType = SqlDbType.DateTime; prm.Size=8; prm.ParameterName = "@date"; prm.Value = _dt; cmd.Parameters.Add(prm); SqlDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { Response.Write(dr["eventTitle"]); } dr.Close(); conn.Close(); } private void Calendar1_SelectionChanged(object sender, System.EventArgs e) { // this code is never executed ... is it in the wrong event ? _dt = Calendar1.SelectedDate; } yes, i'm using code-behind. any hints are welcome. thank you !! Huby. Quote there are 10 kinds of people on earth: those who understand binary, and those who don't.
Moderators Robby Posted July 7, 2004 Moderators Posted July 7, 2004 Do you have the following line in InitializeComponent() this.Calendar1.SelectionChanged += new System.EventHandler(this.Calendar1_SelectionChanged); Quote Visit...Bassic Software
huby Posted July 8, 2004 Author Posted July 8, 2004 Do you have the following line in InitializeComponent() this.Calendar1.SelectionChanged += new System.EventHandler(this.Calendar1_SelectionChanged); yes, i do :( i followed the process step-by-step and the calendar control always returns the value '1/1/1' ... i suppose it loses its value on Postback, but i don't know how i can have him return the date i actually clicked ... thank you for the reply, any more hints are more than welcome !! peace, Huby. Quote there are 10 kinds of people on earth: those who understand binary, and those who don't.
Moderators Robby Posted July 8, 2004 Moderators Posted July 8, 2004 Have you tried placing the LoadEvents call within the IsPostBack block Quote Visit...Bassic Software
huby Posted July 8, 2004 Author Posted July 8, 2004 Have you tried placing the LoadEvents call within the IsPostBack block lol i just logged on to tell you it works, and that is exactly how i solved it :D thanks anyway !! huby. Quote there are 10 kinds of people on earth: those who understand binary, and those who don't.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.