different query for same view showing on different page as list view web part RRS feed

  • Question

  • Hi all,

    If you have three pages and want to add Documents library as list view web part to these three pages with different query (Programmatically), Do you need to create three different views for Documents library or it is possible to have different query when I add the list view web part to the page?

    thanks and appreciate all kind of advice.

    Wednesday, January 8, 2014 11:50 AM


All replies

  • When you add a List View Web Part to a page, SharePoint actually copies the selected view query into the Web Part itself. For example:

    1. You create a custom view on a list called "Mede71's View" and you configure it only show the Title column
    2. You add a List View Web Part to a page and update the settings to use the "Mede71's View"
    3. You go back to your list and change "Mede71's View" and add the "Modified Date" column
    4. Your List View Web Part will not reflect this change because in step 2 the Query from the view was copied into the List View Web Part

    When you programmatically add the List View Web Part, you can either assign it to an existing view or supply the query directly. If you want to instruct users to be able to add their own web parts pointing to those views in the future, I would recommend creating the views first.

    Dimitri Ayrapetov (MCSE: SharePoint)

    Wednesday, January 8, 2014 12:23 PM
  • thank you, How do I apply query directly to LVWP when I create it (programmatically). I cannot find any properperty.
    Wednesday, January 8, 2014 4:21 PM
  • Thanks again,

    I solved it by creating a View modifing its query and add it to the first LVWP. For second LVWP I retrieved the view modified its query saved it and created LVWP based on the view and then changed back the query of the view to original value. I did same for third LVWP.

    • Edited by Medes71 Thursday, January 9, 2014 8:27 AM
    Thursday, January 9, 2014 8:26 AM
  • When you programmatically add the List View Web Part, you can either assign it to an existing view or supply the query directly.


    Thursday, January 9, 2014 8:30 AM
  • it seems you have to write tons of xml to supply query directly
    Thursday, January 9, 2014 8:21 PM
  • It is the same amount of XML when creating the CAML for an SPQuery...

    Dimitri Ayrapetov (MCSE: SharePoint)

    Thursday, January 9, 2014 11:58 PM
  • would you please tell me how do I supply query directly to a List View Web Part? thanks
    Friday, January 10, 2014 8:40 AM
  • The following blog post provides an example: http://sharepointlinks.blogspot.com/2008/05/listviewwebpart-my-own-filter.html

    Dimitri Ayrapetov (MCSE: SharePoint)

    • Marked as answer by Qiao Wei Monday, January 20, 2014 2:33 AM
    Tuesday, January 14, 2014 4:20 PM