我知道在c#4或4.5中可以創建匿名類型和動態類型,但我不確定它是如何工作的。 我遍歷一個SharePoint站點集合,我想爲每個子站點添加一個項目到列表,其中有3列如何創建匿名對象列表
但是我不想爲此創建一個類,因爲它只針對此方法。
private void RenderGrid()
{
string currentUrl = SPContext.Current.Site.Url;
List<object> listobject= new List<object>();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite clientSiteCollection = new SPSite(currentUrl))
{
foreach (SPWeb web in clientSiteCollection.AllWebs)
{
string webtemplate = web.Properties["WebTemplate"];
if (webtemplate.Equals("xx"))
{
SPList xx = web.Lists.TryGetList(Constants.Lists.xx);
if (opportunityInfoList != null)
{
opportunityInfo.Add(new object() {
col1 = "value1",
col2 = "value2",
col3 = "value3"
});
}
}
}
}
});
lastCreatedOpportunitiesGrid.DataSource = opportunityInfo;
lastCreatedOpportunitiesGrid.DataBind();
}
之後,我可以在gridview中使用boundColumn? –
正如我所說,我不確定。你必須自己嘗試一下! –
它表示類型預計在第一個左括號 –