Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

已答复 ListViewByQuery w/ a view using a custom xsl

  • 2012年6月27日 13:41
     
     

    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?

    Thanks!


    Drew Block

全部回复

  • 2012年6月28日 9:14
    版主
     
     已答复

    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;

                 EnsureChildControls();

                 view.RenderControl(writer);

                 RenderChildren(writer);

    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.

    Thanks,


    Qiao Wei

    TechNet Community Support