1
我有一個在foreach循環中運行的數據表,它在多個sahrepoint網站上獲取網站使用信息。我希望能夠在添加網站網址的每個foreach迭代旁邊添加一列,我只能想出如何添加新行,使網站網址顯示在條目下方。像這樣:在數據表中編輯一行C#
我怎樣才能獲得url進入上面行?
我的代碼如下:
SPListItemCollection items = list.GetItems(query);
DataTable aggregatedTable = new DataTable();
foreach (SPListItem item in items)
{
string url = item["SiteUrl"].ToString();
try
{
using (SPSite siteadd = new SPSite(url))
using (SPWeb webadd = siteadd.OpenWeb())
{
//
DataTable table = webadd.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.browser, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);
table.Columns.Add("url");
if (table == null)
{
// HttpContext.Current.Response.Write("Table Null");
}
else
{
DataRow dr;
dr = table.NewRow();
dr["url"] = url;
table.Rows.Add(dr);
// table.Rows.Add(url);
aggregatedTable.Merge(table);//Append the data to previous site data.
}
}
}
catch { }
}
dataGridView1.DataSource = aggregatedTable;//bind datatable with