Hi All,

I have a textbox on my ASPX page the when clicked loads the 'jQuery datepicker' object to select a date. The issue is I want the user to be able to leave the textbox blank if they want all results to be returned when they click the search button. I would like the either set a default date that is hidden or allow the SQL query to ignore the WHERE clause is the textbox = ""

The search button runs a SQL query with a WHERE clause >= the textbox field.



       $(function () {
                 dateFormat: 'dd/mm/yy',
                changeMonth: true,
                changeYear: true


<asp:accessdatasource ID="AccessDataSource1" runat="server" DataFile= "C:\Data.mdb" SelectCommand="SELECT [StartDate], [FirstName], [LastName] FROM [Staff] WHERE [StartDate] >= datepicker )">

Any ideas?


Recommended Answers

All 5 Replies

You could just handle this in your code behind and just check the value of the text box prior to setting up the SQL statement.

In your code you would do this in a subroutine for the click event triggered by a button.

I was trying to have a go at that but wasn't getting very far. Can you point me in the right direction with an example? I can post some additonal code if required.


Ok, so I cant tell from your post where you are trying to backfill the data you get from the database, but to start... you need to have a click event created.

From Design View in Visual Studio, you can just double click the button that you want to trigger the search. That should create your click event.

From there just include an if..then block of code.

So something like this...

VB example...

dim datepicker as string = textBox1.text
if datepicker = "" then
  sqlCommand = "SELECT [StartDate] ..."
  sqlCommand = "SELECT [StartDate] ... WHERE [StartDate] >= datepicker"
end if

Then open the database connection, execute the query, take the results and bind them to the control where you want the results to display, such as a gridview. Or just do whatever else you were planning to do with the results.

I really cant be more specific because I dont have information about your controls, database, etc...

Do some research, you should be able to move forward with this info.

Just add a value to the "Text" attribute. If you need a dynamic entry you can set it from a public method.

<asp:TextBox ID="txtBox" Text="Default Value" runat="server" ></asp:TextBox>

I solved the problem by adding IS NULL to the SQL statement.

FROM [Staff] WHERE (datepicker IS NULL OR [StartDate] >= datepicker)

Thanks for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.