我正在动态加载sharepoint datetimepicker控件,如下所示:
DateTimeControl MyCalendar = new DateTimeControl();
MyCalendar.ID = cldr + arry[0];
MyDynCalendar.DateOnly = false;
And I am reading the values from the control as below , but I only get the date and not the time.
foreach (string crtl in Page.Request.Form)
{
if (crtl.Contains("xxxxx"))
{
ctrlStr = ctl.ToString();
Date Time x = Convert.ToDateTime(Request.Form[ctrlStr]);
}
}
}
I only get the date and not the time selected by the user. Please help!
答案 0 :(得分:1)
为什么不通过DateTimeControl.SelectedDate
属性检索日期?
答案 1 :(得分:1)
为什么不直接使用控件的SelectedDate
属性
答案 2 :(得分:0)
您可以对DateTimeControl使用此通用方法:
/// <summary>
/// Get common SP DateTimeControl with current DateOnly settings and MethodToProcessDateChanged
/// </summary>
public static DateTimeControl Cd(this bool DateOnly, bool AutoPostBack = false,
DateTime? SelectedDate = null, Func<bool> MethodToProcessDateChanged = null)
{
var d = new DateTimeControl();
d.DateOnly = DateOnly;
d.AutoPostBack = AutoPostBack;
if (SelectedDate != null)
d.SelectedDate = SelectedDate.Value;
if (MethodToProcessDateChanged != null)
d.DateChanged += (o, e) => { MethodToProcessDateChanged();};
return d;
}
您可以使用用法示例here
了解更多详细信息