Reputation: 155
I have a textbox
and i would love it to be formatted. fortunately for me, i can get this done by changing the textmode = DateTimeLocal
. Exactly what I want. Additionally, I would like to load this textbox with default values rather than leaving it with dd/mm/yy __:__:__
. I can change the text if it is a regular textbox (single mode
) or even a datetime textbox. but i cannot change it with DateTimeLocal
mode. some help please. thank you.
Upvotes: 1
Views: 11159
Reputation: 1
If you want to set a TextBox's DateTime dynamically from a database then you can use this code:
DataTable dtTemp = (DataTable)ViewState["DataSet"]; // this are temporary table
TextBox txtFromDate = (TextBox)gridEditBloackHomework.Rows[e.NewEditIndex].FindControl("txtFromDate");
TextBox txtToDate = (TextBox)gridEditBloackHomework.Rows[e.NewEditIndex].FindControl("txtToDate");
string c = dtTemp.Rows[e.NewEditIndex]["FromDate"].ToString();
DateTime FromDate = Convert.ToDateTime(dtTemp.Rows[e.NewEditIndex]["FromDate"]);
DateTime ToDate = Convert.ToDateTime(dtTemp.Rows[e.NewEditIndex]["ToDate"]);
DateTime dtFromDate = FromDate.AddHours(-2);
DateTime dtToDate = ToDate.AddHours(-2);
txtFromDate.Text = dtFromDate.ToLocalTime().ToString("yyyy-MM-ddTHH:mm").ToString();
txtToDate.Text = dtToDate.ToLocalTime().ToString("yyyy-MM-ddTHH:mm");
Upvotes: 0
Reputation: 11
Try setting the whole datetime format including seconds and milliseconds, worked for me.
txtStartTime.Text = DateTime.Today.ToString("yyyy-MM-ddTHH:mm:ss.ss");
Upvotes: 1
Reputation: 1463
You will have to format the DateTime to a valid Date and Time string that can be parsed, here is one that works:
txtDateTimeLocal.Text = DateTime.Now.ToLocalTime().ToString("yyyy-MM-ddTHH:mm");
For more details on what other attributes you can set, see: http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#local-date-and-time-state-(type=datetime-local)
Upvotes: 8