【问题标题】:Datetime picker for share point projectsharepoint 项目的日期时间选择器
【发布时间】:2012-04-14 20:30:18
【问题描述】:

有没有人有任何关于如何在共享点项目中放置日期时间选择器的示例? 更具体地说,在gridview中放置一个日期时间选择器.. 我已经在谷歌上搜索了几个小时,但仍然找不到有效的例子.. 大部分示例是针对普通网络项目而不是针对共享点项目..

顺便说一句,我尝试将 datetimecontrol 放在 gridview 中,但效果不佳。

提前致谢。

【问题讨论】:

    标签: sharepoint datetimepicker


    【解决方案1】:

    我喜欢使用 jQuery UI 的 Datepicker:

    http://jqueryui.com/demos/datepicker/

    要在 GridView 中实现,我通常会创建一个可编辑的文本框,然后将类应用于它,这将调用日期选择器:

            <asp:GridView ID="gvClientDetails" runat="server">
                <Columns>
                    <asp:TemplateField HeaderText="Date">
                        <EditItemTemplate>
                            <asp:TextBox runat="server" ID="myTextBox" CssClass="dateTextBox" />
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="myLabel" runat="server" Text='<%# Eval("myDate") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
    

    然后使用以下 javascript(在您的页面或网站范围内注册):

    $('.dateTextBox').each(function () {
        $(this).datepicker(
            {
                changeMonth: true,
                changeYear: true,
                dateFormat: 'yy/mm/dd'
            });
    })
    

    至于将这样的东西应用到您的共享点网站,这应该对您有所帮助:

    http://blogs.lessthandot.com/index.php/WebDev/UIDevelopment/Javascript/adding-a-jquery-date-picker-to-sharepoint

    【讨论】:

      【解决方案2】:

      只需使用通用标准 SP 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

      【讨论】:

        猜你喜欢
        • 2020-07-28
        • 2012-09-11
        • 1970-01-01
        • 2015-04-30
        • 1970-01-01
        • 1970-01-01
        • 2018-11-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多