ListViewByQuery w/ a view using a custom xsl


  • Can you use the ListViewByQuery to display a view that has a custom XSL specified in it's xsllink?

    The view displays properly but when used through the ListViewByQuery it doesn't show up.  Is there somewhere in the ListViewByQuery where you need to specify it is a different XSL?  

    Or do you have to use the XSLTListViewWebPart whenever you are using a non-standard XSL?


    Drew Block

    2012年6月27日 13:41


  • Hi drew,

    ListViewByQuery can be used with view that with custom xsl, I create a view for a list, use SharePoint Designer to add custom  xsl for the view page, then create a web part and add ListViewByQuery control, it works as expected, the code snippet is:
    ListViewByQuery view = new ListViewByQuery();

                 SPWeb currentweb = SPContext.Current.Web;

                 SPList list = currentweb.Lists["list2"];

                 view.List = list;

                 SPView listview = list.Views["myview"];

                 SPQuery query = new SPQuery(listview);

                 query.ViewFields = "<FieldRef Name='Title'/>";

                 query.Query = "<Where><Contains><FieldRef Name='Title'/><Value Type='Text'>q</Value></Contains></Where>";

                 view.Query = query;




    To narrow down the issue, please make sure that you have custom the view correctly. Or you can share your custom xsl for the view to do further research.


    Qiao Wei

    TechNet Community Support

    2012年6月28日 9:14