title: How to use a templatefield item within RowDataBound for GridView
body: <p>ASP.net:</p>
  
  <pre><code>...
  &lt;asp:BoundField HeaderStyle-Width="7%" DataField="Due Date" HeaderText="Due" SortExpression="Due Date" ItemStyle-CssClass="taskTableColumn" /&gt;
  ...
  </code></pre>
  
  <p>C# code (in <code>RowDataDound</code> for <code>GridView</code>):</p>
  
  <pre><code>if (!string.IsNullOrEmpty(e.Row.Cells[4].Text)) //works correctly
  {
      if (DateTime.Parse(e.Row.Cells[4].Text).Date &lt; DateTime.Now.Date)
      {
          e.Row.ForeColor = Color.FromName("#C00000");
          e.Row.ToolTip = "Task is Past Due";
      }
      else if (DateTime.Parse(e.Row.Cells[4].Text).Date &lt;= DateTime.Now.AddDays(inDateOffset).Date)
      {
          //e.Row.ForeColor = Color.FromName("#8A8C00");
          e.Row.ToolTip = "Task is at Risk";
      }
      else
      {
          e.Row.Cells[5].ToolTip = "Task is Not Due Yet";
      }
  }
  </code></pre>
  
  <p>The above ASP.net/C# code worked correctly.</p>
  
  <p>I had to modify the ASP.net to format the field to date:</p>
  
  <pre><code>&lt;asp:TemplateField HeaderStyle-Width="7%" HeaderText="Due" SortExpression="Due Date" ItemStyle-CssClass="taskTableColumn"&gt;
      &lt;ItemTemplate&gt;
          &lt;asp:Label ID="lblDue" runat="server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "Due Date", "{0:MM-dd-yyyy}") %&gt;'&gt;&lt;/asp:Label&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>Now the following line always returns a empty string: <code>if (!string.IsNullOrEmpty(e.Row.Cells[4].Text))</code></p>
  
  <p>How can I modify the C# code so it is able to determine if the date is past due.</p>