我正在使用 Sharepoint 2010,并用 C#/VS2010 编写了一个应用程序页面。我正在使用 ListViewByQuery 来显示一个列表。一切都很好,直到我添加 GroupBy 标记来对列表进行分组。添加后,由于某种原因,我使用 query.ViewFields 选择的列将被忽略,而是在折叠和展开时显示其他三个列。代码在这里:
//this section demonstrates how to display a list in an SP Application Page project:
using (SPWeb web = site.OpenWeb())
{
myListQuery.List = web.Lists["Links"];
SPQuery query = new SPQuery(myListQuery.List.DefaultView);
//note: there seems to be bug somewhere... when the list is grouped by (folders), you
// don't see the fields you request - just three basic fields. It seems to ignore the ViewFields
// that you specified, unless you don't group. Weird.
query.ViewFields = "<FieldRef Name=\"ID\" /><FieldRef Name=\"URLwMenu\" /><FieldRef Name=\"List\" /><FieldRef Name=\"Category\" /><FieldRef Name=\"Author\" />";
query.Query = "<Where><Contains><FieldRef Name=\"List\"/><Value Type=\"Text\">Projects</Value></Contains></Where>";
//if this next line is commented out, all the correct columns are shown
query.Query += "<GroupBy Collapse=\"FALSE\" GroupLimit=\"100\"><FieldRef Name=\"Category\"></GroupBy>";
myListQuery.DisableFilter = false;
myListQuery.DisableSort = false;
myListQuery.Query = query;
}
在此示例中,显示的列是类型、编辑、URL 和注释。如果有人有任何线索,将不胜感激!