GroupBy指定时,ListViewByQuery不显示正确的列

时间:2013-01-04 18:04:21

标签: sharepoint listview sharepoint-2010

我正在使用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;
        }

在此示例中显示的 列是Type,Edit,URL和Notes。如果有人有任何线索,我将不胜感激!

1 个答案:

答案 0 :(得分:1)

您似乎缺少GroupBy子句中FieldRef的结束标记中的/:

<FieldRef Name=\"Category\">