Tuesday, 15 January 2008

ListViewWebPart - Adding Announcements List programatically to sharepoint page

While working with a listviewwebpart in sharepoint the name property should be set to the GUID of the List. The key thing to note is it i s not enough to set the value as GUID.Tostring() but as it is case sensitive it should be set as spListGuid.ToString("B").ToUpper();

The full code is below

ListViewWebPart listWebPart = new ListViewWebPart();
listWebPart.ListName = spListGuid.ToString("B").ToUpper();
webPartManager.AddWebPart(listWebPart, "RightColumnZone", 0);

No comments: