本文介绍了如何以编程方式将WebPart的ViewStyle更改为Default的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以通过以下方式更改Webpart的视图样式:
i can changes the viewstyle of the Webpart this way:
SPSite oSite = new SPSite("http://xxx");
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists["xxx"];SPLimitedWebPartManager oWebPartManager = oWeb.GetLimitedWebPartManager("xxx/Forms/AllItems.aspx", PersonalizationScope.Shared);
ListViewWebPart myWebPart = oWebPartManager.WebParts[0];
SPView view = oList.Views[new Guid(myWebPart.ViewGuid)];
view.ApplyStyle(oWeb.ViewStyles[0]);
view.Update();
oWebPartManager.SaveChanges(myWebPart);
但是我无法设置默认视图样式.
But i cant set the Default viewstyle.
oWeb.ViewStyles的视图样式列表中没有默认视图样式
The Default viewstyle is not available in the viewstyles liste of oWeb.ViewStyles
如何设置默认视图样式?
How can i set the Default viewstyle?
最诚挚的问候,
基督徒
推荐答案
此处是供您参考的代码.跨度>
using (SPSite site = new SPSite("http://sp:12001")) {
using (SPWeb oWebsite =site.OpenWeb())
{
SPList oList = oWebsite.Lists["MyList2"];
SPView oView = oList.Views["All Items"];
string viewxml=oView.GetViewXml();
Regex regex = new Regex("<ViewStyle ID=\"[0-9]{1,2}\"/>");
Match match = regex.Match(viewxml);
oView.SetViewXml(viewxml.Replace(match.Value,""));
oView.Update();
Console.WriteLine("done");
Console.ReadKey();
}
}
最好的问候,
Lee
这篇关于如何以编程方式将WebPart的ViewStyle更改为Default的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!