我正在编写C#代码来合并网站集中的多个库并对其应用分组。但是,分组不包括来自其他站点的文档,无论是否共享相同的元数据。下面,蓝盒文档来自一个站点,绿盒文档来自其他站点,它们不会组合在一起。
这是我的代码,
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc;
SPSite curSite = SPContext.Current.Site;
SPWebCollection subSites = curSite.AllWebs;
dc = new DataColumn("Title", Type.GetType("System.String"));
dt.Columns.Add(dc);
dc = new DataColumn("ReferenceNo", Type.GetType("System.String"));
dt.Columns.Add(dc);
dc = new DataColumn("Domain", Type.GetType("System.String"));
dt.Columns.Add(dc);
dc = new DataColumn("Created", Type.GetType("System.DateTime"));
dt.Columns.Add(dc);
for (int i = 0; i < subSites.Count; i++)
{
SPListCollection lists = subSites[i].Lists;
foreach (SPList list in lists)
{
if (list.Title == "Published Documents")
{
SPQuery myquery = new SPQuery();
//myquery.Query = "<GroupBy><FieldRef Name='Domain' /></GroupBy><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy>";
myquery.Query = "<GroupBy><FieldRef Name='Domain' /></GroupBy>";
SPListItemCollection items = list.GetItems(myquery);
foreach (SPListItem item in items)
{
if (item != null)
{
dr = dt.NewRow();
dr["Title"] = item["Title"];
dr["ReferenceNo"] = item["ReferenceNo"];
dr["Domain"] = item["Domain"];
dr["Created"] = item["Created"];
dt.Rows.Add(dr);
}
}
}
}
}
//dt.DefaultView.Sort = "Created DESC";
spGridView.AllowGrouping = true;
spGridView.AllowGroupCollapse = true;
spGridView.GroupField = "Domain";
spGridView.DataSource = dt;
spGridView.DataBind();
更新:: ,使用域排序数据表修复了问题..
**dt.DefaultView.Sort = "Domain";**
答案 0 :(得分:0)
Rishi的回答:
使用Domain对数据表进行排序修复了问题..
dt.DefaultView.Sort = "Domain";
naveed的评论:
完美对我有用。一切顺利,我们需要
dt.DefaultView.Sort = "Your Sorting Attribute";