无法从日期时间选择器控制共享点获取用户选择的时间

时间:2011-06-07 14:41:27

标签: sharepoint

我正在动态加载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!

3 个答案:

答案 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

了解更多详细信息