I am adding multiple list viewer web parts to a SharePoint [web part] page using the code below:
// Create the object SPLimitedWebPart Manager SPLimitedWebPartManager WebPartMgr = web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared); // Track the zone index (order of placement, starting with zero) of web parts int zoneCounter = 0; // Add "Shared Documents" ListViewer webpart // Get the object of the list of which we are creating the list viewer webpart SPList SharedDocsLst = web.Lists["Shared Documents"]; ListViewWebPart SharedDocsLstViewWP = new ListViewWebPart(); // Set the properties of the webpart SharedDocsLstViewWP.ChromeType = PartChromeType.Default; SharedDocsLstViewWP.ChromeState = PartChromeState.Minimized; SharedDocsLstViewWP.ListName = SharedDocsLst.ID.ToString("B").ToUpper(); SharedDocsLstViewWP.ViewGuid = SharedDocsLst.DefaultView.ID.ToString("B").ToUpper(); // Define the zone in which webparts need to be added WebPartMgr.AddWebPart(SharedDocsLstViewWP, "Body", zoneCounter++); WebPartMgr.SaveChanges(SharedDocsLstViewWP); //.... repeat 9 more times, to add 9 more document library list viewer web parts .... WebPartMgr.Dispose();
The web part added to the page at the 5th position, is actually showing up at the end of the page. In other words, web parts 1-4 reflect the same order as the code. Web part 5 is showing up at the end, i.e. the 10th position. Web part 6-10 are showing up in positions 5-9.
I tried changing the order in the code. Somehow, the behavior is frustratingly consistent... the 5th web part added in the code is showing up at the end on the page. Anybody know why this could be happening?