我尝试在网上搜索以编程方式将列表作为 Web 部件插入到 Web 部件页面中,但并不幸运。
关于如何以编程方式将列表作为 web 部件插入 web 部件页面的任何想法或想法
非常感谢!
最佳答案
首先添加这些 using 语句。
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
然后在你的代码中
// First get the list
SPSite site = new SPSite("http://myserver");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["MyCustomlist"];
// Create a webpart
ListViewWebPart wp = new ListViewWebPart();
wp.ZoneID = "Top"; // Replace this ith the correct zone on your page.
wp.ListName = list.ID.ToString("B").ToUpper();
wp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();
// Get the web part collection
SPWebPartCollection coll =
web.GetWebPartCollection("default.aspx", // replace this with the correct page.
Storage.Shared);
// Add the web part
coll.Add(wp);
如果你想使用自定义 View ,试试这个:
SPView view = list.GetUncustomizedViewByBaseViewId(0);
wp.ListViewXml = view.HtmlSchemaXml;
希望对你有帮助 W0ut
关于sharepoint - 以编程方式将列表作为 Web 部件插入 WSS 3.0 的 Web 部件页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1588019/