Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a Webpart that extends the content query webpart, that is currently pointed to List X. On the click of a button I want that webpart to be changed to point to List Y.

This seems like a very simple requirement, but it apparently isn't :) Does anyone know how to do this?

I have tried:

  • Changing the ListGuid property
  • Changing the ListName property
  • Changing ListOverride property (I didn't do this correctly, as it just threw an error :) )

Any help would be greatly appreciated :)

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Deep in the ether of the interwebs I discovered this gem: http://blog.falchionconsulting.com/index.php/2007/10/retarget-content-query-web-part/

To solve the problem the following code is required:

//set the web url    
cqwp.WebUrl = list.ParentWeb.ServerRelativeUrl;
//set the guid of the list
cqwp.ListGuid = list.ID.ToString();
//set the list title
cqwp.ListName = list.Title;

This allows changing the list the CQWP is pointing to :)

I hope this helps someone!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.