I was adding few XsltListViewWebPart web parts programatically on a web part page. But the web parts were not getting added in proper order. Following is the code which adds XsltListViewWebPart to page.
public static void AddXsltListViewWebPartToPage(SPLimitedWebPartManager wpm, string listName,
string viewName, string zoneId, int zoneIndex, SPWeb web)
{
SPList l = web.Lists[listName];
XsltListViewWebPart xsltWp = new XsltListViewWebPart();
xsltWp.ListName = l.ID.ToString("B").ToUpper();
xsltWp.ViewGuid = l.Views[viewName].ID.ToString("B").ToUpper();
wpm.AddWebPart(xsltWp, zoneId, zoneIndex);
}
Here is how this code was called to add there web parts on a page in the same zone named "ContentZone":AddXsltListViewWebPartToPage(webPartManager, "Internal Contacts", "All Contacts", "ContentZone", 0, web);
AddXsltListViewWebPartToPage(webPartManager, "External Contacts", "All Contacts", "ContentZone", 1, web);
AddXsltListViewWebPartToPage(webPartManager, "Other Contacts", "All Contacts", "ContentZone", 2, web);
But "Other Contacts" was getting added before "External Contacts". After some hit and trial I changed the zone index to start from 1 rather than zero and it worked. Here is the updated code:AddXsltListViewWebPartToPage(webPartManager, "Internal Contacts", "All Contacts", "ContentZone", 1, web);
AddXsltListViewWebPartToPage(webPartManager, "External Contacts", "All Contacts", "ContentZone", 2, web);
AddXsltListViewWebPartToPage(webPartManager, "Other Contacts", "All Contacts", "ContentZone", 3, web);