2

Filtering of a XsltListViewWebPart is absolutely no problem when you change the webPart.XmlDefinition property like this:

                    var xml = new XmlDocument();
             xml.LoadXml(webPart.XmlDefinition); 
            var viewXml = xml["View"]; 
            if (viewXml != null)
             {
                 var viewQuery = viewXml.SelectSingleNode("//Query");

                if (viewQuery != null)
                 {
                     var where = viewQuery.SelectSingleNode("//Where");
                     if (where == null)
                     {
                         where = xml.CreateElement("Where");
                         viewQuery.AppendChild(where);
                     }

                    if (where.ChildNodes.Count == 1)
                     {
                         where.InnerXml = string.Format("<And>{0}{1}</And>", where.FirstChild.OuterXml, query);
                     }
                     else
                     {
                         if (queryCount > 1)
                         {
                             where.InnerXml = string.Format("<And>{0}</And>", query);
                         }
                         else
                         {
                             where.InnerXml = query;
                         }
                     }
                 }} 
webPart.XmlDefinition = xml.InnerXml;

But when the web part is connected to another webpart with a "Send Row of Data To" connection the webPart.XmlDefinition filtering hack doesn’t work any more.

Why?

Your Answer

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

Browse other questions tagged or ask your own question.