title: Set gridview backcolor to color from datatable?
body: <p>I have a <code>datatable</code> that looks like this:</p>
  
  <pre><code>Row1       Row2    Row3    Row4    Row5    Row6
  Gold       Gold              
  Pink       Pink              
  #FB7703    #FB7703               
  Red        Red               
  Yellow                       
  Green                        
  #0B93E1                      
  Purple                       
  </code></pre>
  
  <p>This is what the grid looks like when When I bind the datatable to the grid:
  <a href="https://i.stack.imgur.com/xbowa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xbowa.png" alt="enter image description here"></a></p>
  
  <p>How can set background color of the cells in the gridview to the color in the cell?</p>
  
  <p>I know I need to use <code>RowDataBound</code>.</p>
  
  <p>Markup for gridview:</p>
  
  <pre><code>&lt;div&gt;
      &lt;asp:GridView ID="GridViewClicks" runat="server" 
          onrowdatabound="GridViewClicks_RowDataBound"&gt;
      &lt;/asp:GridView&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And codebehind that fills datatable:</p>
  
  <pre><code>DataTable dataTable = GetColors();
  
  DataTable gridTable = new DataTable();
  gridTable.Columns.Add("Row1", typeof(string));
  gridTable.Columns.Add("Row2", typeof(string));
  gridTable.Columns.Add("Row3", typeof(string));
  gridTable.Columns.Add("Row4", typeof(string));
  gridTable.Columns.Add("Row5", typeof(string));
  gridTable.Columns.Add("Row6", typeof(string));
  
  for (int i = 0; i &lt; 8; i++)
  {
      var r = gridTable.NewRow();
      gridTable.Rows.Add(r);
  }
  
  foreach (DataRow r in dataTable.Rows)
  {
      int rowNum = Convert.ToInt16(r[1]) - 1;
      int colNum = Convert.ToInt16(r[3]);
      gridTable.Rows[rowNum][colNum] = r["color"].ToString();
  }
  
  GridViewClicks.DataSource = gridTable;
  GridViewClicks.DataBind();
  </code></pre>
  
  <p>Thanks.</p>