title: How to add CSS class to asp.net from code behind
body: <p>this is really frustrating and have search a dozen sites:</p>
  
  <p>I have a <code>&lt;asp:table id="questionsTable" runat="server"&gt;</code> to which i dynamically add rows and columns.
  I am trying to add a predefined Cssclass to these newly created rows and columns, but to no avail.</p>
  
  <p>The setup code for the rows and columns:</p>
  
  <pre><code>TableRow row = new TableRow();
  TableCell cell1 = new TableCell();
  TableCell cell2 = new TableCell();
  TableCell cell3 = new TableCell();
  TableCell cell4 = new TableCell();
  TableCell cell5 = new TableCell();
  </code></pre>
  
  <p>I know i can do this:</p>
  
  <pre><code>row.Style.Add("width", "80%");
  row.Style.Add("text-align", "left");
  
  cell1.Style.Add("width", "10px");
  cell2.Style.Add("width", "auto");
  cell3.Style.Add("width", "75px");
  cell4.Style.Add("width", "75px");
  cell5.Style.Add("width", "75px");
  </code></pre>
  
  <p>And it works... but it makes the code-behind file messy.</p>
  
  <p>So i've seen this: </p>
  
  <pre><code>row.Attributes.Add("Class", "rowA");
  
  //CSS - in StyleSheet.css
  .rowA
  {
      width:80%;
      text-align:center;
      background-color:#FCF6CF;
  }
  </code></pre>
  
  <p>But it does not seem to be working for me....</p>
  
  <p>But strangely enough if i look at the markup source generated i get this</p>
  
  <pre><code>    &lt;/tr&gt;&lt;tr Class="rowA"&gt;
  </code></pre>
  
  <p>The above is copied from the rendered page - yet the Css is not being applied... I know the css is correct because if i add it manually it applies it correctly.</p>
  
  <p>EDIT</p>
  
  <p>To all who assisted in this thank you very much. Unfortunately something went wrong and the link to the external stylesheet got deleted. Kudos to Sven for thinking of that. After a long day such as today i to can make beginner mistakes.</p>
  
  <p>thank you once again</p>
  
  <p>Kind regards </p>
  
  <p>Aiden</p>