简体   繁体   中英

How to populate an asp:textbox in TextMode=“DateTimeLocal”

In my ASP.Net app, I have a textbox set to be a datepicker: <asp:TextBox ID="uxDateTimeLocalTextbox" runat="server" TextMode="DateTimeLocal"></asp:TextBox>

在此处输入图片说明

When the user enters the datetime, initially its a string and must be converted to DateTime format before I send it back to my SQL Server table (where that column is in datetime format):

DateTime dateTimeOriginalEmail = Convert.ToDateTime(uxDateTimeLocalTextbox.Text);    

Now, I have created functionality that will do the reverse, and populate the textbox with a value stored in the SQL table. I would think that I need to take that value and convert it back to a string. So, I tried the below (no errors were thrown) but I don't see the textbox being populated with the value from my table. I am using this method on other textboxes and dropdowns and they work fine. Any suggestions on how to get this to work? (Note: MM/DD/YYYY HH:MM AM/PM)

uxDateTimeLocalTextbox.Text = ticketInfo.Rows[0]["DateTimeOriginalEmail"].ToString();

uxDateTimeLocalTextbox.Text = newDate.ToString(“ yyyy-MM-ddTHH:mm”);

this worked for me: (VB code but easy to change to C#)

If IsDate(dr("cnnReminder")) = True Then txtNoteReminderTS.Text = Format(dr("cnnReminder"), "yyyy-MM-ddTHH:mm")

ps. dr is a DataRow and cnnReminder a SQL DateTime

https://stackoverflow.com/a/31854660/2939161 LEM2802 solved it!

txtDate.Text = DateTime.Now.ToLocalTime().ToString("yyyy-MM-ddTHH:mm");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM