title: Comparing and validating a date input with a stored date
body: <p>I have a textbox where a user is inputting a date (line date). If the date they input is greater than a related date (header date) I want asp.net to throw an error. I am trying to do this dynamicly but am getting an error saying cannot convert data type to "date". </p>
  
  <p>ASP.NET CODE (WHERE I AM DOING THE VALIDATION):</p>
  
  <pre><code>&lt;asp:CompareValidator ID="valBidContractEnd" runat="server" Text="*" 
                              ErrorMessage="Error: Bid End Date must be after the effective date of the bid." Type="Date"
                              Display="Dynamic" ValueToCompare='&lt;%#Eval("ContractEndDate", "{0:d}")%&gt;' ControlToValidate="dtEnd" Operator="GreaterThanEqual"/&gt;
  </code></pre>
  
  <p>Where I am reading the date it is comparing to, this is called in page load:</p>
  
  <pre><code>private void LoadContractInfo()
  {
      if (QSContractID.HasValue)
      {
          ContractData data = new ContractData();
          using (IDataReader r = data.ContractGet(QSContractID.Value))
          {
              if (r.Read())
              {
                  lblContractName.Text = r["ContractName"].ToStr();
                  lblContractRefNo.Text = r["ContractRefNo"].ToStr();
                  r["ContractEndDate"].ToDateTime();
              }
          }
      }
  }
  </code></pre>