how i could filter programmatically the xsltlistviewwebpart:

   //this is the web part
    <WebPartPages:WebPartZone runat="server" FrameType="None" ID="WebPartZone1"    
      <WebPartPages:XsltListViewWebPart runat="server" ...>


   <View ...><Query><Where>...</Where></Query><ViewFields>...</ViewFields><RowLimit   
    Default="TRUE">main.xsl</XslLink><Toolbar Type="Standard"/></View>  



      SPWebPartManager wpm = SPWebPartManager.GetCurrentWebPartManager(this.Page) 
        as  SPWebPartManager;

     SPList list = web.Lists["listname"];

      foreach (System.Web.UI.WebControls.WebParts.WebPart current in wpm.WebParts)
          if (current is XsltListViewWebPart)
                XsltListViewWebPart XsltListViewWebPart1 = current as 

               StringBuilder xml = new StringBuilder();
     xml.Append("<View Name='" + 

    + "' TabularView='FALSE' MobileView='TRUE' Type='HTML'  Hidden='TRUE' 
     DisplayName=''  Level='1' BaseViewID='1' ContentTypeID='0x' ImageUrl='/_layouts
    /images/generic.png'>");   Url='" + Request.Url.ToString() + "' 
   xml.Append("<Query><Where><Eq><FieldRef Name='LinkFilename'/><Value Type='Text'> " 
   + name + " </Value></Eq></Where><OrderBy><FieldRef Name='ID'/></OrderBy></Query>");
   xml.Append("<ViewFields><FieldRef Name='LinkFilename'/><FieldRef   
   xml.Append("<RowLimit Paged='TRUE'>20</RowLimit>");

    XsltListViewWebPart1.XmlDefinition = xml.ToString();

  • I have no idea what you're trying to do. The XSLTListViewWebpart needs a dataconnection that contains a CAML query. You can add filters to that CAML query? But that is not what you want? – Christoffel de Gruyter Aug 19 '14 at 10:52
  • i made sth like this: for XmlDefinition but does not work – ezzaam Aug 19 '14 at 10:56
  • Can you explain what exactly the requirements are? I mean, the XSLTListViewWebpart has all the filter capabilities you should need. – Christoffel de Gruyter Aug 19 '14 at 11:25
  • the requirement is to filter this web part show only some items : precisely the user might filter by items name bias with textbox above the web part grid. – ezzaam Aug 19 '14 at 11:28
  • you could see Query tag in xml definition – ezzaam Aug 19 '14 at 11:29

This isn't really an answer to your question, but I just want to get this out of the way to make sure you're not making things too difficult for yourself.

XSLTListViewWebparts already have very extensive filtering capabilities which you can very easily talk to by clicking on the sort button on top of each column.

If you want to talk to it directly, you can use the querystring. Just use the following format:


This is for a list/library view, but this querystring can be used anywhere.

You can also connect it by using any kind of Filter webpart and connect both webparts to each other. (These are available in the enterprise edition of SharePoint, to enable them, enable the enterprise feature). Choice Filter, Business Data Catalog Filter, SharePoint List Filter, etc.

| improve this answer | |
  • Don't forget to mark my post as answer if it works for you and or upvote if it's usefull. Thanks – Christoffel de Gruyter Aug 19 '14 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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