2013-01-04 21 views
0

我正在使用Sharepoint 2010,並在C#/ VS2010中編寫了一個應用程序頁面。我正在使用ListViewByQuery來顯示一個列表。一切都很好,直到我添加GroupBy標籤來分組列表。當添加時,出於某種原因,我用query.ViewFields選擇的列將被忽略,而在摺疊和展開時會顯示其他三列。代碼是在這裏:當GroupBy指定時,ListViewByQuery不顯示正確的列

  //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; 
     } 

的列,顯示,在這個例子中,有型,編輯,網址,和註釋。如果任何人有任何線索,將不勝感激!

回答

1

你似乎缺少在FieldRef的結束標記/中的GroupBy子句中:

<FieldRef Name=\"Category\"> 
+0

Rawbert,你搖滾!非常感謝,就是這樣。將fieldref部分更改爲