title: How can I customize the style of the autogenerated columns of a GridView?
body: <p>I have a <strong>GridView</strong> and I need to be able to <strong>set the style for the autogenerated columns,</strong> particularly I will need to set the <strong>width</strong> of each column. How can I do that?</p>
  
  <p>Thanks for replies!</p>
  
  <p><strong>SOLUTION UPDATE:</strong></p>
  
  <p>(thanks to Stephan Bauer)</p>
  
  <p>Add event on DataGrid</p>
  
  <pre><code>OnDataBound="ItemsBound"
  </code></pre>
  
  <p>In the event set the width:</p>
  
  <pre><code>protected void ItemsBound(object sender, EventArgs e)
  {
      (sender as GridView).Rows[0].Cells[0].Width = Unit.Pixel(150);
  }
  </code></pre>
  
  <p>Or you can do:</p>
  
  <pre><code>(sender as GridView).Rows[0].Cells[0].Style.Add("width", "150px");
  </code></pre>
  
  <p>to set any other css property.</p>