我尝试在网上搜索以编程方式将列表作为 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);
如果您想使用自定义视图,请尝试使用以下命令:
SPView view = list.GetUncustomizedViewByBaseViewId(0);
wp.ListViewXml = view.HtmlSchemaXml;
希望能帮助到你,
乌特
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)