Click here to Skip to main content
15,898,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to be able to extract value from datepicker textbox and pass those value into my sql query.

This is my datepicker textbox:
<p>DatePicker: <asp:TextBox ID="TextBox2" runat="server" /></p>

However the code below, is showing the following error:
'string' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

C#
string txtDate = TextBox2.Text;
string theDate = txtDate.Value.ToString("yyyy-MM-dd");

I tried using DateTime type as well and then converting it to string but that still gives me the same error on the Value property.

Thank you for any further help.
Posted

Use the following to be sure that you have actually added date in the text box and then parse it:

C#
string txtDate = TextBox2.Text;
DateTime date;
string theDate;
if (DateTime.TryParse(txtDate, out date))
{
   theDate = date.ToString("yyyy-MM-dd");
}


now theDate variable will have your date in string format. You can use date variable it self if you want date as DateTime
 
Share this answer
 
v2
Try this:

string txtDate = TextBox2.Text;
DateTime myDate = DateTime.Parse(txtDate );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900