Pointing ListViewWebParts at lists

I was creating a site definition recently, and I wanted to use a ListView web part in it. List View Web Parts are a little strange; unlike other web parts they’re represented by a ‘View’ element inside the ‘File’ element for a page; it’s sort of saying that we want a view onto a list shown on this page. Looking at the out-of-box site definitions, they show things like:

<View List="104" BaseViewID="0" WebPartZoneID="Left" />

Here the ‘List’ attribute is the ‘Type’ id of the List, as defined in the list definition. Great – but what if (as in my case) you have two separate lists of the same type?

Well, it turns out that it also accepts a relative URL too. As the documentation says…

List – Optional Integer or Text. Specifies the type of list. This value can be either the ID of the template for a list (an integer), or the URL to a list provisioned in the site (a string). Best practice is to use Text, because Integer might not be specific enough (e.g., if there are two announcements lists in the site and you specify List=104).

So we can use:

<View List="Comments" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="1" />

Here the ‘List’ attribute is set to ‘Comments’, which is the URL to my ‘Comments’ list (no, it isn’t the name – ‘cos this list’s display name is ‘Case Comments’). And this works nicely. This is actually how some of the out-of-box site defintions work, but most of them refer to their lists by type.

Pointing ListViewWebParts at lists

2 thoughts on “Pointing ListViewWebParts at lists

  1. boomshanka says:

    Hi Andy,

    Do you know if it’s possible to customize the webpart surrounding the ListView? Let’s say for instance that I wanted to make sure no users could close the ListView, I would modify the webpart and uncheck “AllowClose”. Is this possible to define in a onet.xml file?

  2. Not sure off the top of my head – but it should be possible though the Object Model. That’s a bit of a programmer task, though.

    Or, you could change the settings of your Web Part Zone through SharePoint Designer to not allow normal users to edit it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.