通过Calendar控件指定日期实现数据查询
1、分别添加Calendar控件和GridView控件
2、Calendar控件事件代码:
protected void Calendar1_SelectionChanged(object sender, EventArgs e) { if (this.calendar3.SelectedDate != null) { string connectiongString = WebConfigurationManager.ConnectionStrings["Database"].ConnectionString; SqlConnection con = new SqlConnection(connectiongString); con.Open(); Response.Write("打开数据库成功!"); Label1.Text = calendar3.SelectedDate.ToShortDateString(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = string.Format("select * from DateDemo where 日期='{0}'", this.calendar3.SelectedDate.ToString()); //注意参数{0}要用单引号括起来‘{0}’ SqlDataAdapter adpt = new SqlDataAdapter(); adpt.SelectCommand = cmd; DataSet ds = new DataSet(); adpt.Fill(ds); con.Close(); this.GridView1.DataSource = ds; this.GridView1.DataBind(); } }


![clip_image002[1] clip_image002[1]](http://images0.cnblogs.com/blog/535139/201306/03165323-e4f84a1e89b844c4a9f77f04c129dbe1.jpg)
![clip_image002[3] clip_image002[3]](http://images0.cnblogs.com/blog/535139/201306/03165325-5191f8ffec9946468a42ff9e9545bdd6.jpg)
浙公网安备 33010602011771号