Set the Title of a ListViewWebPart

Something that has bothered me repeatedly in the past is that ListViewWebParts didn’t seem to allow their titles to be set via CAML. The View element for a site (i.e. in the ONET.xml file) doesn’t have a title element, and the ‘Name’ and ‘DisplayName’ elements don’t set the web part’s title. Instead, the ListViewWebPart always seemed to pick up the name of the list it referred to. This was a problem if you had a page that showed two ListViewWebParts refering to the same list. E.g.:

<View List="Lists/Tasks" BaseViewID="7" WebPartZoneID="Left" WebPartOrder="5" />
<View List="Lists/Tasks" BaseViewID="9" WebPartZoneID="Left" WebPartOrder="6" />

would result in:

How can we set those titles to be different? Continue reading “Set the Title of a ListViewWebPart”

Advertisements
Set the Title of a ListViewWebPart

Weird toolbar on Custom Document Library

I’ve been writing a custom document Library Definition. Well, I say I was writing – I actually created it in SharePoint, and used the Solution Generator in the Visual Studio Extensions for WSS3 to produce the CAML and .aspx files.

Having done this, however, one of the views in my document library was a bit strange. Somehow, for this one view, the ‘New’ and ‘Upload’ menus were missing:

Weird View (BaseType 3)

They were there for other views, just not this one. After examining the CAML (which sounds like some sort of euphemism) I found that the problem seemed to relate to the BaseViewID for the view. Continue reading “Weird toolbar on Custom Document Library”

Weird toolbar on Custom Document Library

The Summary Toolbar in a ListView Web Part

Yesterday I was describing adding a ListView Web Part pointing at a specific view. I had a ListView Web Part which showed the right columns, but also showed the full toolbar:

case-comments-listview-2

…and I had a ListView which showed the Summary Toolbar, but didn’t show the right columns:

case-comments-listview-1

The Web Parts are defined identically, except for the BaseViewID property. So, what gives? Continue reading “The Summary Toolbar in a ListView Web Part”

The Summary Toolbar in a ListView Web Part

Pointing the ListViewWebPart at a particular view

So yesterday I described adding a ListViewWebPart to a Site Definition. This works – but how do you point the web part at a particular view?

This took a little figuring out. My ListViews were being defined in my ONET.xml file as:

<View List="Comments" BaseViewID="0" WebPartZoneId="Left">

Clearly the BaseViewID was a likely candidate – but what did it point to, and how could I define a view for my ListView? As is stood, My ListView kept appearing as:

case-comments-listview-1

Well, BaseViewID isn’t well documented, but it is actually the ID number of a view in the List Definition. I can’t say that I was able to see how to define a view for out ListView within our Site Definition itself.

If we open up our List Definition’s schema.xml file we see:

case-comments-list-definition-views

You can see that each of the views is assigned assigned a BaseViewID. I tried changing my BaseViewID to ‘1’ and my web part’s view changed to:

case-comments-listview-2

Great! This show’s the extra column I wanted – but it also shows the toolbar, which I didn’t. I really wanted the Summary Toolbar (the ‘Add new Item’ link, as in the top screenshot), but I’ll describe how I got that tomorrow.

Pointing the ListViewWebPart at a particular view

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