我有以下webpart添加了gridview控件。 现在我需要将绑定列添加到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();
}