#sharepoint
#sharepoint
Вопрос:
Я загружаю элемент управления выбора даты и времени sharepoint динамически, как показано ниже:
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!
Ответ №1:
Почему вы не извлекаете дату через DateTimeControl.SelectedDate
свойство?
Ответ №2:
Почему вы не используете непосредственно SelectedDate
свойство элемента управления
Ответ №3:
Вы можете использовать этот общий метод для 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;
}
Вы можете ознакомиться с более подробной информацией о примерах использования здесь