title: INT converted to boolean updateable in a checkbox
body: <p>I have been programming for many years, about 10 in an older version of .NET, as a result I'm new to LINQ, UpdatePanels and Ajax and their way of doing things.<br>
  The following code works correctly.<br>
  The database field is defined as:<br></p>
  
  <pre><code>rptPriority INT NOT NULL DEFAULT(0)
  </code></pre>
  
  <p>A much simplified page stub which works is:</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="upReport" runat="server" UpdateMode="Conditional"&gt;
      &lt;ContentTemplate&gt;
          &lt;fieldset&gt;
          &lt;asp:DetailsView ID="dvReport" runat="server" DataSourceID="ldsReport" CssClass="reset"
              AutoGenerateRows="False" DefaultMode="Edit" Width="100%"&gt;
              &lt;Fields&gt;
                  &lt;asp:TemplateField&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:DynamicControl ID="Priority" runat="server" DataField="rptPriority" Mode="Edit" CssClass="general" /&gt;
  </code></pre>
  
  <p>etc<br>
  What I need to do is change that Dynamic Control as a textbox to a checkbox which is updatable and driven by the same data. The following gives the correct data but doesn't update.<br>
  Were I doing this using straight SQL or PROCEDURES, this would not be a big problem. (also not an option)</p>
  
  <pre><code>&lt;asp:CheckBox ID="Priority" runat="server" Checked='&lt;%# Convert.ToBoolean(Eval("rptPriority")) %&gt;' /&gt;
  </code></pre>
  
  <p>I changed "Eval" to "Bind" and got the "ERROR CS0103: The name 'Bind' does not exist in the current context"<br>
  I suspect that the "Convert.ToBoolean" is part of the problem.<br>
  There are many pages which I've perused trying to get the info I need. Among them <a href="https://stackoverflow.com/questions/16319629/how-to-add-checkbox-to-datagrid-in-vb-net">How to add checkbox to datagrid in vb.net</a> , <a href="https://stackoverflow.com/questions/4718356/html-checkbox-returns-false-if-disabled-even-if-seleced">Html.CheckBox returns false if disabled, even if seleced</a> and <a href="https://stackoverflow.com/questions/7238639/checkbox-server-client-events">Checkbox server/client events</a> , <a href="https://stackoverflow.com/questions/1876719/how-do-you-know-to-use-container-dataitem-when-data-binding-in-asp-net-is-there">How do you know to use Container.DataItem when data binding in ASP.NET? Is there a reference?</a> , <a href="https://stackoverflow.com/questions/7866066/the-databind-bind-function-belongs-to-which-class">The databind bind() function belongs to which class?</a> not to mention about 50 more outside of stack overflow which got me to where I am now.<br>
  <b>Edit</b><br>
  As per Rob's suggestion, I added the following, but couldn't get / find any way to use "DetailsViewUpdateEventArgs".</p>
  
  <pre><code>protected void dvReport_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
  {
      DetailsView dv = sender as DetailsView;
      CheckBox ctlPriority = dv.FindControl("Priority") as CheckBox;
      e.NewValues["rptPriority"] = ctlPriority.Checked ? 1 : 0;
  }
  </code></pre>
  
  <p>The following is a stub from the save / update code behind.</p>
  
  <pre><code>protected void btnSave_OnCLick(object sender, EventArgs e)
  {
    RadioButtonList rblReportStatus = (RadioButtonList)dvReport.FindControl("rblReportStatus");
  
    using (RiderReportDataContext db = new RiderReportDataContext())
    {
      Report report = null;
      Contact contact = null;
      DateTime now = DateTime.Now;
      bool doUpdate = false;
  
      ldsContact.Updating += (o, ea) =&gt;
      {
        Contact original = (Contact)ea.OriginalObject;
        contact = (Contact)ea.NewObject;
  
        if (
          original.FirstName != contact.FirstName ||
  ...
          original.Email != contact.Email)
        {
          doUpdate = true;
        }
  
        db.Contacts.Attach(contact, original);
  
        ea.Cancel = true;
      };
  
      // force the update procedure
      dvContact.UpdateItem(true);
  
      ldsReport.Updating += (o, ea) =&gt;
      {
        Report original = ea.OriginalObject as Report;
        report = ea.NewObject as Report;
  
        if (rblReportStatus.SelectedItem != null)
        {
          report.ReportStatusId = int.Parse(rblReportStatus.SelectedValue);
        }
  
        if (
          original.ReportStatusId != report.ReportStatusId ||
          original.SourceId != report.SourceId ||
  ...
          original.ReportTypeID != report.ReportTypeID ||
          original.rptPriority != report.rptPriority ||       // The value here doesn't change
          original.SupervisorId != report.SupervisorId)
        {
          doUpdate = true;
        }
        db.Reports.Attach(report, original);
        ea.Cancel = true;
      };
  
      // force the update procedure
      dvReport.UpdateItem(true);
  
  // Other Search For Updates
  
      if (doUpdate)
      {
        contact.ChangedOn = now;
        report.ChangedOn = now;
  
        Log log = new Log();
        log.ReportId = report.Id;
        log.UserId = MembershipClass.User.Id;
        log.Text = "The report updated.";
        log.CreatedOn = now;
        report.Logs.Add(log);
  
        db.SubmitChanges();
      }
    }
  
    if (Page.IsValid)
    {
      Response.Redirect("~/default.aspx" /*table.ListActionPath */);
    }
  }
  </code></pre>