I would first like to describe the scenario and then would give you the approach to achieve it so that it will be easy to understand the solution. Scenario – Requirement is to create a reusable web part that can be added on different pages just like the other out of box SharePoint web parts. Also, the desired web part should fetch content from a list and the content should be different for different pages e.g. if the title of the page is MOSS then the displayed content should be related to MOSS and if the title is SP2010 then the content should change accordingly. So basically on changing the page property the content of the web part should change.
Options: Two web parts – Data View Web Part (DVWP) and Content by Query Web Part (CQWP) can be used for such requirements, but I chose CQWP because of following reasons:
a. Easy to configure the web part properties such as sorting and filtering without going to code.
b. Filters can be mapped with page properties using web part properties.
Now let’s see how to make the CQWP as a reusable web part.
Step 1
Create a List “Reusable List” with Columns – Title, Description, Category. Add some items to the list. This list will be used as the source to the CQWP.
Step 2
Create a page “Reusable Page” add a CQWP on it.
Step 3
Edit the Web part properties and set the properties.
Query:
i. Source – Add “Reusable List” as the source.
ii. Additional Filters – Set Filter as below.
Now the Additional Filter will do the trick for you. Here the Category column of the list has been mapped with the Title of the Page. So change in the Title will change the content displayed in the Web Part. Note: If you want to map the list column value with you choice of column say ‘Page Category’ then you have to create a Content Type with your choice of column “Page Category” and add this Content Type to the Pages Library. Select your content type for the page using “Edit Properties” of the Page.
Step 4
Save the webpart.
Set the Page ‘Title’ in ‘Edit Properties’ of the page to change the content in the CQWP. Now you have configured the Web Part to meet the requirement. Now lets us make this web part Reusable throughout the Site Collection by uploading it in Web Part Gallery.
1. Export the above created CQWP Web Part.
2. Go to the Site Settings of the Site Collection.
3. Click Web Parts under Gallery section on the setting page.
4. Upload the exported Web Part.
5. Go to any page. Edit it and click Add a Web Part link.
6. Choose your reusable Web Part.
7. Change the Title of the page to SP2010 or MOSS or SPD as per the category defined in Reusable List.
Enjoy SharePoint!

























