title: asp.net gridview formatting
body: <p>I have a gridview which has three columns date, pnl, cumpnl
  I am able to add some formatting when applied to all cells using code such as</p>
  
  <pre><code>Protected Sub OnRowCreated(sender As Object, e As GridViewRowEventArgs)
      If e.Row.RowType = DataControlRowType.DataRow Then
          For Each cell As TableCell In e.Row.Cells
              cell.Font.Size = 10
              cell.HorizontalAlign = HorizontalAlign.Center
          Next
      End If
  
  End Sub
  </code></pre>
  
  <p>Within that For...Next loop how can I reference only the cells in the pnl and cumpnl columns? I don't see anyway to reference cells by the columnheader name or index.</p>
  
  <p>Update:</p>
  
  <p>by Using a RowDataBound event I can now reset the format of the values in the columns but the setting of the forecolor based on the cells value keeps erring ("Input string not in correct format"). Also, I am hardcoding the the column indexes. I need a way to dynamically get the column index based on the column header name</p>
  
  <pre><code>Protected Sub gvDataRetrieval_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDataRetrieval.RowDataBound
      If e.Row.RowType = DataControlRowType.DataRow Then
          For i As Integer = 1 To 2
              e.Row.Cells(i).Text = FormatCurrency(e.Row.Cells(i).Text, 2).ToString()
              If Double.Parse(e.Row.Cells(i).Text) &lt; 0 Then e.Row.Cells(i).ForeColor = Drawing.Color.Red
          Next
   End If
  End Sub
  </code></pre>