title: ASP.NET Change Text and Color in Gridview cell in a Template Field
body: <p>I have Gridview in ASP.net that displays data. Depending on the data it changes color and text depending on the value of the cell.
  This works fine when a column is NOT a template field.</p>
  
  <pre><code> //WORKS WHEN IS NOT A TEMPLATE FIELD
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
          if (e.Row.Cells[2].Text == "1")
          {
  
             e.Row.Cells[2].Text = "IN";
             e.Row.Cells[2].BackColor = Color.Blue;
             e.Row.Cells[2].ForeColor = Color.White;
          }
  
    }
  </code></pre>
  
  <p>Now I converted the Column in to a Template field and nothing works.</p>
  
  <pre><code>     //DOEST NOT WORK WHEN IS a TEMPLATE FIELD
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
           if (e.Row.Cells[2].Text == "1")
           {
  
               e.Row.Cells[2].Text = "IN";
               e.Row.Cells[2].BackColor = Color.Blue;
               e.Row.Cells[2].ForeColor = Color.White;
           }
  
       }
  </code></pre>
  
  <p>I GOT THE COLOR WORKING, but now I need to change the Text to the following. IF statusID == 1 then display IN, else if statusID == 2 then display OUT</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText="StatusID" SortExpression="StatusID"&gt;
                              &lt;EditItemTemplate&gt;
                                  &lt;asp:DropDownList ID="DropDownList1" runat="server" SelectedValue = '&lt;%# Bind("StatusID") %&gt;'&gt;
                                      &lt;asp:ListItem Value="1"&gt;IN&lt;/asp:ListItem&gt;
                                      &lt;asp:ListItem Value="2"&gt;OUT&lt;/asp:ListItem&gt;
                                  &lt;/asp:DropDownList&gt;
                              &lt;/EditItemTemplate&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="lblStatus" runat="server" Text='&lt;%# Bind("StatusID") %&gt;' ForeColor='&lt;%# Convert.ToString(Eval("StatusID")) == "1" ? System.Drawing.Color.Green: Convert.ToString(Eval("StatusID")) == "2" ? System.Drawing.Color.Red: System.Drawing.Color.Purple%&gt;'&gt;&lt;/asp:Label&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>Any of you know how to solve this issue. Thanks in advance.</p>