Hi, i have a Gridview that displays records by using a button click after specifying date range. My requirement is to display data when page loads using todays date. NB: I have a hidden textbox in the form that captures today's date. Any help?
Thank you
Vishal JoshiPosted Jan 4, 2023, 1:22 PM
Hello Ahmed,
You can try the below code to get the expected result.
Thanks
Ahmed KhalidPosted Jan 5, 2023, 6:03 PM
Dear Vishal,
I have applied your suggestion, it works properly. however, when i deployed in live, the grid with today's date selection is never displayed. I deployed the same code as in development and testing environment. Any idea where the issue is?
Thanks & Rgrds
Ahmed KhalidPosted Jan 5, 2023, 7:39 AM
Hi Sachin,
I have modified but it still shows the error in the textbox reference as shown in attachment. I have verified that the text field ID for the hidden textbox in the form is exactly the same
Sachin SinghPosted Jan 5, 2023, 6:19 AM
@Ahmed, it should be
Ahmed KhalidPosted Jan 4, 2023, 5:38 PM
I have modified my procedure as below:
but i am getting error in '" + txt_hiddenDate.Text + "'
noting that txt_hiddenDate is a textbox ID in the form and is displaying default Today's date on page load
Sachin SinghPosted Jan 4, 2023, 10:15 AM
simply in you stored procedure keep the datetime column default value GetDate() so that for initial load without parameters it will fetch the current date records only
Aravind GovindarajPosted Jan 4, 2023, 9:08 AM
Create a common method with input as a date parameter to load the data, which suppose to be called from the OnPageLoad event and Button click event. In OnpageLoad pass the input from hidden text box, if it has value take the value otherwise pass it as datetine.now. While doing the button click, prompt alert if you wana to do, like input is empty. otherwise apply the same logic, take the specific date range otherwise get today datetime. hope this helps you
Pasang TamangPosted Jan 4, 2023, 8:54 AM
Hi,
It should work by using same code that you have used in button click. You have to use same code in page load. Date Range value you can use today's date DateTime.Now. You can check this example also https://www.aspsnippets.com/questions/528010/Filter-ASPNet-GridView-using-DataView-for-Date-range-using-C-and-VBNet/
Regards,
Pasang