从datepicker中提取值 [英] extract value from datepicker
问题描述
我希望能够从datepicker文本框中提取值并将这些值传递给我的sql查询。
这是我的日期选择器文本框:
< p> DatePicker:< ; asp:TextBox ID =TextBox2runat =server/>< / p>
但是下面的代码,显示以下 错误 :
'string'不包含'Value'的定义,也没有扩展方法可以找到'value'接受'string'类型的第一个参数(你是否缺少using指令或汇编引用?)
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?)
string txtDate = TextBox2.Text;
string theDate = txtDate.Value.ToString("yyyy-MM-dd");
我尝试使用 DateTime
类型,然后将其转换为字符串,但仍然在 Value
属性上给出了相同的错误。
感谢您的进一步帮助。
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.
推荐答案
使用以下内容确保您确实拥有在文本框中添加日期,然后解析它:
Use the following to be sure that you have actually added date in the text box and then parse it:
string txtDate = TextBox2.Text;
DateTime date;
string theDate;
if (DateTime.TryParse(txtDate, out date))
{
theDate = date.ToString("yyyy-MM-dd");
}
现在 theDate
变量将在字符串中显示您的日期格式。如果你希望日期为DateTime
now theDate
variable will have your date in string format. You can use date
variable it self if you want date as DateTime
,你可以使用date
变量。试试这个:
Try this:
string txtDate = TextBox2.Text;
DateTime myDate = DateTime.Parse(txtDate );
这篇关于从datepicker中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!