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:
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:
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:
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.
hey thanks, I ran in some ListView problems. Your post was a step in the right direction for me.
I posted my experiences here
http://lawo.wordpress.com/2009/07/18/list-view-in-site-definition/
Yup, a good tip – if you’re getting an error, check the URL your list is under, and what your ListView is pointing at. Often SharePoint creates lists under the ‘/Lists/’ folder in the virtual file system – but you don’t have to.
(“Comments” in the example above is not in the /Lists/ folder for example)