Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

Update

        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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.