问两个弱弱的关于XsltListViewWebPart和ContentEditorWebPart的有关问题
问两个弱弱的关于XsltListViewWebPart和ContentEditorWebPart的问题
我在一个WebPart中加了如下代码,把当前网站上所有LIST用XsltListViewWebPart显示出来
XsltListViewWebPart xlvWebPart = null;
foreach (SPList currList in currWeb.Lists)
{
if (currList.BaseType.CompareTo(SPBaseType.GenericList) == 0)
{
xlvWebPart = new XsltListViewWebPart();
xlvWebPart.ListId = currList.ID;
xlvWebPart.Title = currList.Title;
this.LayoutPanelMain.Controls.Add(xlvWebPart);
}
}
不过遇到一个问题,就是显示出的LIST 下面没有toolbar 显示 add new item链接,请问怎么让他显示,
还有个问题怎么用C#代码给ContentEditorWebPart里增加html内容
------解决方案--------------------
1. 将某个list作为web part添加到某个页面应该用如下代码:
http://blog.brianfarnhill.com/2008/03/add-a-list-view-web-part-to-a-page-with-code
2. ContentEditorWebPart只能写HTML和Javascript, CSS等前台代码的。
------解决方案--------------------
参考这段代码:
我在一个WebPart中加了如下代码,把当前网站上所有LIST用XsltListViewWebPart显示出来
XsltListViewWebPart xlvWebPart = null;
foreach (SPList currList in currWeb.Lists)
{
if (currList.BaseType.CompareTo(SPBaseType.GenericList) == 0)
{
xlvWebPart = new XsltListViewWebPart();
xlvWebPart.ListId = currList.ID;
xlvWebPart.Title = currList.Title;
this.LayoutPanelMain.Controls.Add(xlvWebPart);
}
}
不过遇到一个问题,就是显示出的LIST 下面没有toolbar 显示 add new item链接,请问怎么让他显示,
还有个问题怎么用C#代码给ContentEditorWebPart里增加html内容
------解决方案--------------------
1. 将某个list作为web part添加到某个页面应该用如下代码:
http://blog.brianfarnhill.com/2008/03/add-a-list-view-web-part-to-a-page-with-code
2. ContentEditorWebPart只能写HTML和Javascript, CSS等前台代码的。
------解决方案--------------------
参考这段代码:
if (myItem.Name.ToUpper() == "DEFAULT.ASPX")
{
SPLimitedWebPartManager webPartCollection = myItem.File.GetLimitedWebPartManager(PersonalizationScope.Shared);
PublishingPage myPage = PublishingPage.GetPublishingPage(myItem);
myPage.CheckIn("if checked out");
myPage.CheckOut();
int u = webPartCollection.WebParts.Count;
for(int i=0;i<=u;i++){
Microsoft.SharePoint.WebPartPages.WebPart webpt = (Microsoft.SharePoint.WebPartPages.WebPart)webPartCollection.WebParts;
if (webpt.GetType().ToString() == "Microsoft.SharePoint.WebPartPages.ContentEditorWebPart"){
//Create an XmlElement to hold the value of the Content property.
ContentEditorWebPart ceWebPart = new ContentEditorWebPart();
// Create an XmlElement to hold the value of the Content property.
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlElement = xmlDoc.CreateElement("Content");
xmlElement.InnerText = ((
ContentEditorWebPart)webpt).Content.InnerText.ToString();