开发者

Unable to get the time selected by user from Date Time Picker Control Sharepoint

I am loading the sharepoint datetimepicker control dynamical开发者_运维问答ly as below:

            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!


Why don't you retrieve the date via the DateTimeControl.SelectedDate property?


Why don't you use directly the SelectedDate property of the control


You can use this common method for 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;
}

You can take a look on more details with usage samples here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜