SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to add Sharepoint List Filter Web Part to page.

I'm not sure if it is Microsoft.SharePoint.Portal.WebControls.SpListFilterWebPart. How to add it to the page and configure?


        SpListFilterWebPart listfilter = new SpListFilterWebPart();
        listfilter.ListUrl = web.ServerRelativeUrl + "/StatisticsFiles";
        listfilter.ValueFieldGuid = fields.GetFieldByInternalName("ID").Id;
        listfilter.DescriptionFieldGuid = fields.GetFieldByInternalName("Title").Id;
        listfilter.ViewGuid = web.Lists.TryGetList("StatisticsFiles").Views["All Items"].ID;

        wpman.AddWebPart(listfilter, "Zone3", 2);

wpman.AddWebPart(listfilter, "Zone3", 2); --> here is a mistake as listfilter is Portal.WepControl, how to add it to the collection

Thank you for help

share|improve this question
Lena, try using GenericWebPart listfilterWebPart = wpman.CreateWebPart(listfilter); before wpman.AddWebPart – Arsalan Adam Khatri Nov 7 '12 at 9:54

Use the following approach

1.) Create a visual webpart

2.) First add the following on the .ascx page

Code for .ascx page

<SharePoint:ListViewByQuery runat="server" ID="customlistview" /> 

3.)Add the following code to query your list(assuming you have created the site and web objects)

Code for .ascx.cs page

 SPList list = web.Lists.TryGetList("list_name");
 customlistview.List = list;
 SPQuery query = new SPQuery(customlistview.List.DefaultView);
 query.Query = "<Where>....Use your filtering query here.....</Where>";
 customlistview.Query = query;
share|improve this answer

Basically if this is an OOTB webpart or a web part which you created, you have to create an instance of it in your code.

Then you have to add this instactance to a webpart collection in a webpart manager on the page.

Check this link out

share|improve this answer
Thank you fo answer. I have updated the question according to your answer. Check it, please. – Lena Nov 7 '12 at 7:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.