views:

222

answers:

3

I have a Contact List web part I developed that is dependent on a custom list I created, also called Contact List. But instead of the web part ALWAYS requiring a list called Contact List whenever the web part is added to a page, I want it so I can add the web part to a page THEN set which list I want it to use. I guess I am asking how do you create custom properties for a web part, much like the baked-in properties of web parts you get when you click on the web part and then click Modify Shared Web Part.

The reason I want to do this is because I intend on adding a List Template called Contact List Template. Them, whenever I want to display a contact list, I just create a specific list from the list template, then tie that new list to my web part that displays the list.

I envision it would work like this: 1. I create a contact list from Contact List Template, say "Sales Contact List" 2. I then add the Contact List web part to the page 3. Finally, I set the web part's custom property (let's call it ContactListSourceList) to "Sales Contact List" 4. The web part then works as it currently does where it retrieves the data from the list and displays it.

BTW, I speak VB better than C#, although I can figure out C# if I have to. Any help would be greatly appreciated.

+1  A: 

Sounds like you want to create a WebPart with Custom Properties. The following articles should help:

mundeep
A: 

That works! Thanks!

D-Frag
np's you may then want to mark the answer as accepted see http://stackoverflow.com/questions/279995/accepting-answers-what-is-it-all-about
mundeep
A: 

For anyone else out there that may need to do this, I wrote a How-to on my solution, which tells about creating a custom property but also goes into what to show the user when the property is not set or not set properly. How to set a SharePoint web part's list at run time