我有以下添加了 gridview 控件的 webpart。现在我需要将绑定的列添加到gridview。我怎样才能做到这一点?
protected override void CreateChildControls()
{
base.CreateChildControls();
lastCreatedOpportunitiesGrid = new GridView();
this.Controls.Add(lastCreatedOpportunitiesGrid); ///?here??
RenderGrid();
}
#region Private methods
private void RenderGrid()
{
string currentUrl = SPContext.Current.Site.Url;
List<dynamic> opportunityInfo = new List<dynamic>();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite clientSiteCollection = new SPSite(currentUrl))
{
foreach (SPWeb web in clientSiteCollection.AllWebs.Where(c => c.Properties["WebTemplate"] == "xx").OrderByDescending(d => d.Created).Take(5))
{
SPList opportunityInfoList = web.Lists.TryGetList(Constants.Lists.OpportunityInfoName);
if (opportunityInfoList != null)
{
opportunityInfo.Add(new
{
OpportunityName = opportunityInfoList.Items[0]["Opportunity Name"],
OpportunityCode = opportunityInfoList.Items[0]["Opportunity Code"],
CsLink = opportunityInfoList.Items[0]["CS Link"]
});
}
web.Dispose();
}
}
});
lastCreatedOpportunitiesGrid.DataSource = opportunityInfo;
lastCreatedOpportunitiesGrid.DataBind();
}