Any body know how to filter calendar? I tried these code

protected override void CreateChildControls()

    using (SPWeb web = SPContext.Current.Site.OpenWeb("/test"))
        SPList list = web.GetListByUrl("/Lists/TestCalendar");
        SPView view = list.Views["Calendar"];

        ListViewWebPart webPart = new ListViewWebPart();

        webPart.WebId = web.ID;
        webPart.ListId = list.ID;
        webPart.PageType = PAGETYPE.PAGE_DEFAULTVIEW;
        webPart.ViewContentTypeId = "0x";
        webPart.ListViewXml = GetViewXml(view);


private string GetViewXml(SPView view)
    if (ApplySearch)
        view.Query = "my custom query";

    return view.GetViewXml();

It works fine for any view except Calendar. I cannot understand What the difference and how can i solve this issue.

  • What is "my custom query", there can be a problem in CAML Query, please post it as well Commented Dec 17, 2012 at 15:31
  • @ArsalanAdamKhatri, This query is not complex and it works correctly. I'm sure because I tested this query on all items view of my calendar list.
    – Alexander
    Commented Dec 17, 2012 at 16:15


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.