locked
Programmatically changing the Selected-View for a WebPart List RRS feed

  • Question

  • Hi,

    - I created a webpart page in WSS 3.0
    - Added 2 Web Parts, the first one is a SmartPart and the second is a WebPart list. The list is a custom list named Product.

    What I want to do is to write some code in the SmartPart web part to filter a specific private view linked to this Product custom list through a CAML query. I did that and it is working fine. So when I change the filter in this SmartPart code I am able to see the changes take effect in the Product private view.

    What I want now is to be able to reflect these changes dynamically on the WebPart list containing the Product list

    I am able to do that manually if I select to edit the Web Part then reselect the source view for this web part. But the question is how can I do that programmatically

    Here is my proposed code:

    Dim manager As WebPartPages.SPLimitedWebPartManager = web.GetLimitedWebPartManager("http://SPServer:9090/sites/DEV/Shared%20Documents/CustomPage2.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared)

    Dim webPart As Microsoft.SharePoint.WebPartPages.WebPart

    For Each webPart In manager.WebParts

    If webPart.Title = "Product" Then

       ' Here I want to change the source view of this web part or change it`s filter dynamically

    End If

    Next webPart

    Sunday, November 16, 2008 9:53 AM

Answers

  • One way might be to not use the webpart view of the list on your form. Instead, build yourself a custom spgridview. Then you can manipulate the spgridview as you wish. It will be a lot of work to build the spgridview (compared to using the out of the box list webpart views). But, you will have complete control and it will look just like the out of the box list webpart view.

    Now you would have 2 custom webparts. And, you can use the webpart connection technique to pass information from one webpar to the other. So, the filter webpart could send parameters to the spgridview webpart and the spgridview can query the list appropriately to fill itself in.

    I also have a second idea. While I was writing this I thought - what if the content query webpart could be used with connection filter information. So, I did a quick search and found this article: http://msmvps.com/blogs/laflour/archive/2008/05/29/subclassing-content-query-web-part-to-override-caml-query.aspx. The content query webpart would take the place of your list view webpart. This should be a lot easier than creating a custom spgridview.

    Monday, March 2, 2009 6:54 PM

All replies

  • Check out this post: http://stsadm.blogspot.com/2007/11/update-list-view.html

    Download the code you'll have everything you need to be able to update a list view programmatically using the API.

    Tuesday, November 18, 2008 5:03 AM
  • Hi,

    I am not really sure if I am missing something here. But, we have already managed to control an ordinary list view filter through SharePoint SDK & CAML queries. The problem is how to programmatically change the filter of a list that is used by a webpart. Because, from what I understand is that when you add a list-webpart for a specific custom list and select a view for this webpart from the already available views for this custom list, SharePoint seems to make a snapshot copy of this view for this webpart, so afterwards if you change the filter for the original list-view the list that appears in this webpart will not be affected!! It seems like it becomes another view specifically for this webpart!!

    Do you see the dilema ??

    Tuesday, November 18, 2008 3:24 PM
  • I have the same dilemma. Have you ever found out how to to do this. I have update some 150+ webparts and this would be a better option.
    Friday, February 20, 2009 8:54 AM
  • Unfortunately no :-((
    Monday, March 2, 2009 6:16 PM
  • One way might be to not use the webpart view of the list on your form. Instead, build yourself a custom spgridview. Then you can manipulate the spgridview as you wish. It will be a lot of work to build the spgridview (compared to using the out of the box list webpart views). But, you will have complete control and it will look just like the out of the box list webpart view.

    Now you would have 2 custom webparts. And, you can use the webpart connection technique to pass information from one webpar to the other. So, the filter webpart could send parameters to the spgridview webpart and the spgridview can query the list appropriately to fill itself in.

    I also have a second idea. While I was writing this I thought - what if the content query webpart could be used with connection filter information. So, I did a quick search and found this article: http://msmvps.com/blogs/laflour/archive/2008/05/29/subclassing-content-query-web-part-to-override-caml-query.aspx. The content query webpart would take the place of your list view webpart. This should be a lot easier than creating a custom spgridview.

    Monday, March 2, 2009 6:54 PM