1

I was trying the following but it says that the header row is null?>

   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();
    }

2 Answers 2

4

I think you should be setting CssClass in the HeaderStyle property:

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

The HeaderRow property gives you the GridView's header after the databinding. Check http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.headerrow.aspx: "The HeaderRow property is available only after the GridView control creates the header row in the RowCreated event."

Sign up to request clarification or add additional context in comments.

Comments

-1

try this

lastCreatedOpportunitiesGrid.HeaderRow.CssClass = "your_class_name";

1 Comment

you cant do that as I explained the HeaderRow object is null at that moment. Paolo answer solved it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.