在 WSS 3.0 中的 webpart 页面中以编程方式插入列表作为 webpart [英] Programmatically insert a List as a webpart in a webpart page in WSS 3.0
本文介绍了在 WSS 3.0 中的 webpart 页面中以编程方式插入列表作为 webpart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在网上搜索以编程方式在 webpart 页面中插入一个 List 作为 webpart,但不够幸运.
I tried searching on the net to programmatically insert a List as a webpart in a webpart page but was not lucky enough.
我如何以编程方式将列表作为 webpart 插入 webpart 页面的任何想法或想法
非常感谢!
推荐答案
首先添加这些 using 语句.
First add these using statements.
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);
如果你想使用自定义视图,试试这个:
If you want to use a custom view, try playing with this:
SPView view = list.GetUncustomizedViewByBaseViewId(0);
wp.ListViewXml = view.HtmlSchemaXml;
希望有帮助,W0ut
这篇关于在 WSS 3.0 中的 webpart 页面中以编程方式插入列表作为 webpart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文