【发布时间】:2015-02-16 06:51:44
【问题描述】:
我在 Visual Studio 2013 中创建了可视化 Web 部件。我想阅读
- 列表字段标题
- 列出数据
我正在阅读第一个列表字段标题正确的其余部分是随机数,我不确定我在哪里做错了
我的清单
我的 C# 类
protected void Page_Load(object sender, EventArgs e)
{
using (SPSite _site = new SPSite(SPContext.Current.Web.Site.Url))
{
using (SPWeb _web = _site.OpenWeb())
{
SPList _list = _web.Lists["MyUWLContent_List"];
SPView _view = _list.DefaultView;
//Get a collection of view field names.
StringCollection _viewFields = _view.ViewFields.ToStringCollection();
// Print the value of each view field.
foreach (string fieldName in _viewFields)
{
Label1.Text += fieldName + "<BR>";
}
} //end SPWeb
} //end SPSite
}
但我正在从 Web 部件获得以下输出
【问题讨论】:
-
附带说明,您应该使用
SPContext.Current.Web而不是打开新的 SPWeb 对象。这将避免 useles 数据库往返。 -
是SPContext.Current.Web会解决问题吗???
-
很好,为什么有人在这个问题上给我打分;真的有什么问题???????????????????????????
标签: asp.net sharepoint-2013 web-parts