ListViewWebPart and ToolbarType
How can I can remove or hide the toolbar for a ListViewWebPart that's added programatically?
There are ways to do this like taking the output from HtmlSchemaXml or ListViewXml, then replace <Toolbar Type="Standard" /> with <Toolbar Type="None" /> or whatever it might be and update the webpart in the webpart collection. This works most of the time when the webparts on the page have these values.
Is there a simpler way? Yes...
This is the typical code to add a ListViewWebPart to webpart page.
1. Dim myweb As SPWeb = New SPSite("http://MOSS").OpenWeb
2. Dim ResumeList As SPList = myweb.Lists("Resumes")
3. Dim wp As ListViewWebPart = New ListViewWebPart()
4. wp.ListName = ResumeList.ID.ToString("B").ToUpper
5. wp.ViewGuid = ResumeList.DefaultView.ID.ToString("B").ToUpper()
6. Dim currentManager As SPLimitedWebPartManager = myweb.GetLimitedWebPartManager("default.aspx", WebParts.PersonalizationScope.Shared)
7. Dim aWebPartCollection As SPLimitedWebPartCollection = currentManager.WebParts
8. currentManager.AddWebPart(wp, "Left", 1)
When we specify the webpart.ViewGuid, a default schema is added which contains tag for Toolbar. This causes the Toolbar to be displayed in the webpart page.
All you have to do is not to specify the webpart.ViewGuid and this does the trick.