calendar events

huby

Freshman
Joined
Feb 20, 2004
Messages
32
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 :

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.
 
Do you have the following line in InitializeComponent()
this.Calendar1.SelectionChanged += new System.EventHandler(this.Calendar1_SelectionChanged);
 
Robby said:
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.
 
Robby said:
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.
 
Back
Top