简体   繁体   English

如何使用C#.net从数据库中检索日期值并在HTML5输入类型“日期”中进行设置?

[英]How to retrieve Date value from Database using C#.net and set in HTML5 input Type 'date'?

I want to retrieve date from database and set into HTML5 input type 'date'. 我想从数据库中检索日期并将其设置为HTML5输入类型“日期”。 I have two HTML5 date fields with IDs 'CourseStartDate' and 'CourseEndDate', and using the following code but couldn't getting the value in HTML5 date. 我有两个HTML5日期字段,其ID为“ CourseStartDate”和“ CourseEndDate”,并使用以下代码,但无法获取HTML5日期中的值。

   CourseStartDate.Value  = coursedr["Start_Date"].ToString();
   CourseEndDate.Value    = coursedr["End_Date"].ToString();

You should try to convert the date time into specific format accepted by HTML5 control. 您应该尝试将日期时间转换为HTML5控件接受的特定格式。

CourseStartDate.Text = DateTime.UtcNow.ToString("yyyy-MM-dd");

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTML5输入类型日期未从ASP.NET Core 1.1中的控制器加载日期值 - HTML5 input type date is not loading the date value from the controller in ASP.NET Core 1.1 如何使用C#.NET Winform从SQL Server Compact数据库检索返回行值 - How to retrieve return row value from a SQL Server Compact database using C#.NET winform 在日期类型c#.net上比较验证器 - Comparevalidator on date type c#.net 如何在ASP.NET中从数据库到文本框检索日期值 - How to retrieve date value from database to textbox in asp.net 如何在 .net 中设置今天的输入类型日期默认值 - how do set input type date default value today in .net 如何从XML到C#.NET的序列化日期 - How to do Serialization date from XML to C#.NET C#.net如何完全忽略/消除datetimepicker中的日期值? - C#.net How to ignore/eliminate date value from datetimepicker altogether? 从c#.net中的数据库加载数据时如何将组合框值设置为null或为空 - How to set combobox value to null or empty while loading data to it from database in c#.net 不使用日期时“无法将MySQL日期/时间值转换为System.DateTime”-C#.Net - 'Unable to convert MySQL date/time value to System.DateTime' WHEN not using a date - C#.Net 从代码隐藏中将值设置为 input type="date" - Set value to input type=“date” from codebehind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM