1

我正在尝试以下操作,但它说标题行为空?>

   private void CreateGridControl()
   {
        lastCreatedOpportunitiesGrid = new GridView();

        BoundField bOportunityCode = new BoundField();
        bOportunityCode.DataField = "OpportunityCode";
        bOportunityCode.HeaderText = "OpportunityCode";
        lastCreatedOpportunitiesGrid.Columns.Add(bOportunityCode);

        BoundField bOpportunityName = new BoundField();
        bOpportunityName.DataField = "OpportunityName";
        bOpportunityName.HeaderText = "OpportunityName";
        lastCreatedOpportunitiesGrid.Columns.Add(bOpportunityName);

        HyperLinkField bCSLink = new HyperLinkField();
        bCSLink.DataNavigateUrlFields = new string[] {"CsLink"};
        bCSLink.HeaderText = "CsLink";
        bCSLink.Text = @"<img src='" + ResolveUrl("/_layouts/15/xx/xx/Images/cs.gif") + "' /> ";
        lastCreatedOpportunitiesGrid.Columns.Add(bCSLink);

        lastCreatedOpportunitiesGrid.HeaderRow.CssClass = Constants.CssClasses.HeaderRow;
        lastCreatedOpportunitiesGrid.RowStyle.CssClass = Constants.CssClasses.Row;
        lastCreatedOpportunitiesGrid.AutoGenerateColumns = false;

        lastCreatedOpportunitiesGrid.EmptyDataText = Constants.Messages.NoOpportunitiesFound;

        this.Controls.Add(lastCreatedOpportunitiesGrid);
        LoadGridData();
    }
4

2 回答 2

4

我认为你应该CssClassHeaderStyle属性中设置:

lastCreatedOpportunitiesGrid.HeaderStyle.CssClass = Constants.CssClasses.HeaderRow;

HeaderRow属性在数据绑定后为您提供 GridView 的标题。检查http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.headerrow.aspx:“HeaderRow 属性仅在 GridView 控件在 RowCreated 事件中创建标题行后可用。”

于 2013-06-07T08:20:00.927 回答
-1

尝试这个

lastCreatedOpportunitiesGrid.HeaderRow.CssClass = "your_class_name";
于 2013-06-07T09:37:06.463 回答