Execute a select query based on the chosen date from the CalendarExtender

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.

Answer №1

To accurately match the columns in date and value, make sure to cast them appropriately.

In your SqlCommand query, ensure you are casting the Date column as a date type and matching it with the @CalenderDate parameter.

The value of the @CalenderDate parameter should correspond to the selected date from the Calendar Extender component.

cmd.Parameters.AddWithValue("@CalenderDate",Convert.ToString(CalendarExtender1.SelectedDate));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to dynamically apply the "active" class to a Vue component when it is clicked?

Here is the structure of my Vue component: Vue.component('list-category', { template: "#lc", props: ['data', 'category', 'search'], data() { return { open: false, categoryId: this.category ...

Issue with React application and nginx configuration causing components not to switch when using router functionality

I have encountered an issue while trying to deploy my React app using nginx. The problem I am facing is that when I change routes, for example to /about, the front end does not update and remains on the index page. Here is the configuration in sites-avai ...

The browser has the ability to execute scripts prior to processing any post requests

When it comes to handling post requests, browsers have the ability to process scripts. Imagine you have the following scenario: if (some true condition) { console.log("ready to post") restangular.all.post(RequestData).then(function(response){ ...

Retrieving the record in Postgresql where a specific column value is unique to a specific group

Here is the structure of my Postgresql TABLE: CREATE TABLE foo(man_id, subgroup, power, grp) AS VALUES (1, 'Sub_A', 4, 'Group_A'), (2, 'Sub_B', -1, 'Group_A'), (3, 'Sub_A', 5, 'Group_A&a ...

The query limit issue in Sails JS

I am encountering a 413 (Request Entity too large) error when making a request to a Sails Js app (v0.12). Despite my attempts to raise the request limit in the bodyParser, I have not seen any changes take effect. In config/http.js, I included a customize ...

Is it possible for me to adjust the size of the Facebook login button on my website?

I have implemented a Facebook login on my website using the following code: <fb:login-button scope="public_profile,email" onlogin="checkLoginState();"> </fb:login-button> Is it possible to replace this button with a standard button or adjust ...

Utilizing Fullcalendar 5 in conjunction with Angular: Embedding Components within Events

Recently, my team made the transition from AngularJS to Angular 12. With this change, I upgraded Fullcalendar from version 3 to version 5 and started using the Angular implementation of Fullcalendar: https://fullcalendar.io/docs/angular While navigating t ...

Converting a .NET Framework 4.6.1 class library to .NET Core 3.1: Step-by-step guide

<PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> What property should I add or update to convert my class library to a .NET Core 3.1 library? ...

Guide on scheduling a daily API GET request in a Node.js script for 11:00pm

I am working on a node js application that involves making an AWS API GET call. http://localhost:3000/amazon/api Within this call, I have specified the necessary functionalities. My goal is to automate this call to run everyday at 11:00PM using node js ...

Javascript: A Fun Game of Questions and Answers

When using JavaScript exclusively, I have an array consisting of four questions, four correct answers, and four incorrect answers. The use of arrays is essential to maintain order in the data. As each question is displayed, a random number is generated by ...

Error in Postman: Express and Mongoose throwing 'name' property as undefined

While trying to create and insert 'user' JSON documents according to the model below, upon sending a POST request to localhost:3000/api/student, I encountered an error using Postman: TypeError: Cannot read property 'name' of undefined ...

Error Alert: Request missing connection details while trying to connect to Sql server via express.js

I am currently utilizing the most recent versions of node, express, and mssql module. My objective is to establish a connection with the local instance of SQL Server 2014 through express.js. Following the guidelines provided in the official documentation, ...

Consistent height for h2 containers across all CSS grid columns

Is there a way to ensure all h2 containers have the same height, both with JavaScript and without it? The h2 titles are dynamic and can vary in length, but I want to maximize the space for all containers. img { max-width: 100%; height: auto; } .gri ...

Problem with the WP Rocket helper plugin that excludes JS scripts from Delay JS only at specific URLs

Looking for assistance with a helper plugin that excludes scripts from "Delay Javascript Execution"? You can find more information about this plugin here. The specific pages where I want to exclude slick.min.js and jquery.min.js are the home page and tabl ...

In Javascript, a function is executed only once within another function that is set on an interval

Using the Selenium Chrome driver in my JavaScript, I am constantly checking a value on a website every 2 seconds. However, I need to only save status changes to a text file, not every single check. The current code is functional but it saves the text fil ...

Encountering Issues with JQuery Mobile When Loading Wicket's BookmarkablePageLink

I'm a newcomer to JQuery Mobile and trying to implement it in my Apache Wicket-based application to enhance the mobile user experience. However, I'm facing "Error Loading Page" issues when clicking on page links, which never occurred before integ ...

Verify whether a specific point in time falls within the same week as any date string within an array of date strings

I am working on my backbone-app copyCLDRView and I am trying to replicate weeks along with their components and data. In simpler terms, I want to "copy one week and all its models into another week." My goal is to check if the target week has at least one ...

Using React-Testing-Library to Jest TestBed Hook in TypeScript for Jest Testing

I'm currently facing a challenge while attempting to integrate the react-hooks library with Formik, specifically using useFormikContext<FormTypeFields>() in TypeScript within my project. I have certain fields where I want to test the automation ...

Storing a Mongoose value as a date: best practices

Whenever I store a date in Mongoose, it always gets saved as a string. let currentDate = new Date().toISOString(); let item = await Item.findOne({}); item.details.expiryDate = currentDate; await item.save(); After checking the database ...

What steps should I take to create an in-site product filtering system with multiple dropdowns by utilizing a JSON file?

I have created an in-site redirect tool for our E-Commerce platform by utilizing resources from this website. I am looking to enhance the functionality of these in-site redirects by implementing a JSON file that contains options tailored to our existing li ...