I have a list of lists and an empty XsltListViewWebPart. When the user clicks on a list in the list of lists, I'd like to show that list inside the XsltListViewWebPart. How can I change the underlying list of an XsltListViewWebPart?
This is the code I've tried so far:
using (SPSite spSiteTest = new SPSite("http://MySite"))
{
using (SPWeb web = spSiteTest.OpenWeb())
{
SPList boardrooms = web.Lists["Boardrooms"]; // Boardrooms is just an arbitrary list I've chosen for testing purposes
SPView view = boardrooms.Views["Test"];
listViewWebPart.ListId = boardrooms.ID;
listViewWebPart.ViewGuid = view.ID.ToString();
listViewWebPart.XmlDefinition = view.GetViewXml();
//update spWeb object
web.Update();
}
}
The list view shows up initially, but when I click the button that this method is attached to, I get an error saying that the specified view is invalid. I've specifically designed the view (it's just all the columns and items in the list), and in the Visual Studio debugger have verified that it's been instantiated.
This is the code for my XsltListViewWebPart:
<WebPartPages:XsltListViewWebPart id="listViewWebPart" runat="server"></WebPartPages:XsltListViewWebPart>