开发者

Add the Date Filter SharePoint webpart to an ASP.Net page

How do I add the out-of-the-box SharePoint date filter webpart to an ASP.Net web page?

I want to do it either in an ASPX...

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

or programmatically, in the ASPX.CS

protected void Page_开发者_开发百科Load(object sender, EventArgs e)
{
 this.Controls.Add(<Microsoft.Something.DatePicker??>
}


In your code behind add a reference to Microsoft.Sharepoint and Microsoft.Sharepoint.WebControls

Then declare DateTimeControl dtc;

In your page Load or Page Init just use dtc=new DateTimeControl(); this.Controls.Add(dtc);

This should add the datecontrol. Let me know if u face some issue


It will be easier to use standard SharePoint DateTimeControl. Here is a common method for this with DateTimeControl, hope it will help someone with the same issue.

/// <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;
}

See more details on how to use it here

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜