Is there a way to execute a select query based on the selectedDate value of CalendarExtender in an ASP.NET application? There is a hidden dummy button that triggers a button click event on the Calendar Extendar using
OnClientDateSelectionChanged="checkDate"
and the respective javascript function "checkDate" is:
<script type="text/javascript>
function checkDate(sender, args) {
var Clientdate = sender._selectedDate;
__doPostBack('Button1', '');
} </script>
The code behind file for the button click event contains the following:
protected void Button1_Click(object sender, EventArgs e)
{
String cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
gvAlreadyAllocated.Visible = true;
SqlCommand cmd = new SqlCommand("select Date,EmpName,TimeSlot,Topic,ClassroomNo from tblTimeSlotDetails where Date=@CalenderDate", con);
con.Open();
cmd.Parameters.AddWithValue("@CalenderDate",);
using (SqlDataReader rdr = cmd.ExecuteReader())
{
DataTable dt = new DataTable();
dt.Columns.Add("Date");
dt.Columns.Add("Name");
dt.Columns.Add("TimeSlot");
dt.Columns.Add("Topic");
dt.Columns.Add("Classroom Number");
while (rdr.Read())
{
DataRow dataRow = dt.NewRow();
dataRow["Date"] = Convert.ToString(rdr["Date"]);
dataRow["Name"] = rdr["Empname"];
dataRow["TimeSlot"] = rdr["TimeSlot"];
dataRow["Topic"] = rdr["Topic"];
dataRow["Classroom Number"] = rdr["ClassroomNo"];
dt.Rows.Add(dataRow);
}
gvAlreadyAllocated.DataSource = dt;
gvAlreadyAllocated.DataBind();
}
}
}
How can the @Calenderdate parameter be passed with a value?
cmd.Parameters.AddWithValue(@CalenderDate,);
The goal is to display a gridview where the selectedDate matches the date in the database.