我知道在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? –
正如我所说,我不确定。你必须自己尝试一下! –
它表示类型预计在第一个左括号 –