【问题标题】:Add the Date Filter SharePoint webpart to an ASP.Net page将日期筛选器 SharePoint webpart 添加到 ASP.Net 页面
【发布时间】:2011-02-19 08:31:23
【问题描述】:

如何将现成的 SharePoint 日期过滤器 Web 部件添加到 ASP.Net 网页?

我想在 ASPX 中执行此操作...

<%@ Register Assembly="<DateFilterDLL??>" Namespace="<??>" TagPrefix="DP" %>
<...>
        <asp:WebPartManager ID="WebPartManager1" runat="server">
        </asp:WebPartManager>
<...>
 <ZoneTemplate>
        <DP:<DateFilterWebPart??> ID="DateFilter" runat="server" />

或以编程方式,在 ASPX.CS 中

protected void Page_Load(object sender, EventArgs e)
{
 this.Controls.Add(<Microsoft.Something.DatePicker??>
}

【问题讨论】:

    标签: sharepoint filter datepicker web-parts aspnet-compiler


    【解决方案1】:

    在您的代码后面添加对 Microsoft.Sharepoint 和 Microsoft.Sharepoint.WebControls 的引用

    然后声明 DateTimeControl dtc;

    在您的页面加载或页面初始化中,只需使用 dtc=新日期时间控制(); this.Controls.Add(dtc);

    这应该添加日期控件。如果您遇到问题,请告诉我

    【讨论】:

    • 谢谢,但这不只是将 DateTime 控件添加到 Web 部件吗?然后您必须添加方法和属性才能将 Web 部件变成过滤器?但是,sharepoint 中已经有一个日期时间过滤器 Web 部件。我正在尝试将其添加到 ASPX 页面(请参阅我的第一个 aspx 页面 - 这是一个设置为接受 webpart 控件的 aspx 页面,我想将 DateTime 过滤器 web 部件添加到其中)。
    【解决方案2】:

    使用标准的 SharePoint DateTimeControl 会更容易。 这是 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

    【讨论】:

    • 感谢您的回答。我希望其他人觉得它有帮助。我已经离开 SharePoint 一段时间了,所以无法评估它。欢迎使用 StackOverflow!
    猜你喜欢
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2022-01-20
    • 2015-12-12
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多