title: How do I set css classes for a gridview row and header by code?
body: <p>I was trying the following but it says that the header row is null?></p>
  
  <pre><code>   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 = @"&lt;img src='" + ResolveUrl("/_layouts/15/xx/xx/Images/cs.gif") + "' /&gt; ";
          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();
      }
  </code></pre>