0

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??>
}
Stephen Hosking
  • 1,405
  • 16
  • 34

2 Answers2

1

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

Abhishek Rao
  • 93
  • 1
  • 3
  • 13
  • Thanks, but doesn't that only add a DateTime control to a web part? And then you have to add the methods and attributes to turn the web part into a filter? However, there's alread a Date Time filter web part in sharepoint. I'm trying to add it to an ASPX page (pls see my first aspx page - it's an aspx page set up to accept webpart controls, and I want to add the DateTime filter web part to it). – Stephen Hosking May 17 '10 at 06:12
1

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

  • Thanks for the answer. I hope others find it helpful. I've been away from SharePoint for a while now, so am not able to evaluate it. Welcome to StackOverflow! – Stephen Hosking Mar 20 '19 at 11:00