0

我有以下添加了 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();


        }
4

1 回答 1

0

在网格视图中从代码后面添加绑定字段阅读代码项目文章

希望对你有效。

于 2013-06-05T08:53:23.050 回答