title: Dynamically changing a table cell background color in asp.net
body: <p>I have the following table row on my .aspx page: </p>
  
  <pre><code>&lt;tr&gt;
          &lt;td valign="bottom" style="width: 157px"&gt;Initial Requirements:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
          &lt;asp:Repeater ID="Repeater11" runat="server" DataSourceID="ObjectDataSource1"&gt;
  
          &lt;ItemTemplate&gt;
           &lt;td valign="bottom" id="ReqStatus" runat="server" style="background-color: Gray"&gt;
           &lt;%#ReqStatus(CType(CType(Container.DataItem, System.Data.DataRowView).Row, DataSet1.DataTable1Row))%&gt;
  
           &lt;/td&gt;
  
         &lt;/ItemTemplate&gt;
         &lt;/asp:Repeater&gt;
  
          &lt;/tr&gt; 
  </code></pre>
  
  <p>In the code behind I have this function:</p>
  
  <pre><code>Protected Function ReqStatus(ByVal Project As DataSet1.DataTable1Row) As String
          'Dim ReqTableCell As TableCell
          'ReqTableCell = form1.FindControl("ReqStatus")
  
  
          ' Check the status of the Development Completed
          Dim rightNow As Date = Now()
          Dim dateDifference As TimeSpan
          If Not Project.IsNull("Requirements_Target") Then
  
              Dim ReqTargetDate As Date = Project.Requirements_Target
  
              If Project.IsNull("Req_Date") Then
                  dateDifference = ReqTargetDate.Subtract(rightNow)
  
                  If dateDifference.Days &gt; 0 Then
  
                      If dateDifference.Days &gt;= 60 Then
                          'ReqTableCell.BackColor = Drawing.Color.Green
                          Return "&lt;strong&gt;&lt;font color='green'&gt;" &amp; dateDifference.Days &amp; "&lt;/font&gt;&lt;/strong&gt;"
                      ElseIf dateDifference.Days &gt; 30 And dateDifference.Days &lt; 60 Then
                          'ReqTableCell.BackColor = Drawing.Color.Yellow
                          Return "&lt;strong&gt;&lt;font color='yellow'&gt;" &amp; dateDifference.Days &amp; "&lt;/font&gt;&lt;/strong&gt;"
                      Else
  
                          'ReqTableCell.BackColor = Drawing.Color.Red
                          Return "&lt;strong&gt;&lt;font color='red'&gt;" &amp; dateDifference.Days &amp; "&lt;/font&gt;&lt;/strong&gt;"
                      End If
  
                  Else
                      'ReqTableCell.BackColor = Drawing.Color.Red
                      Dim pastDue As Int16 = (dateDifference.Days * -1)
                      Return "&lt;strong&gt;&lt;font color='red'&gt;" &amp; pastDue &amp; "&lt;/font&gt;&lt;/strong&gt; days past"
  
                  End If
              End If
          Else
  
          End If
      End Function
  </code></pre>
  
  <p>I can change the color of the return value based on conditional statements but cannot figure out the correct syntax to change the table cell back ground. My attempt is commented out.</p>
  
  <p>How do I correctly declare the table cell?  Findcontrol must not be the correct way.</p>