title: Update SQL from Checkbox in ListView
body: <p><strong>Goal</strong>: Update row(s) in SQL table when Checkbox inside ListView is clicked.
  I would like to update the following columns from sql: 
  IsApproved
  ApprovalType</p>
  
  <p>I am able to find the checkbox in the row that is clicked from the Listview on the page. However, that is as far as I got. Current code below, as well as what I've tried and the subsequent errors.</p>
  
  <hr>
  
  <p><strong>Code</strong>:</p>
  
  <p><strong>aspx</strong>:</p>
  
  <pre><code>&lt;asp:ListView ID="lstUsers" runat="server" ItemType="Program.Data.Table" DataKeyNames="ID" SelectMethod="lstUsers_GetData"
      OnItemCommand="lstUsers_ItemCommand" DeleteMethod="lstUsers_DeleteItem" OnSorting="lstUsers_Sorting"
      OnItemDataBound="lstUsers_ItemDataBound"
      ItemPlaceholderID="litPlaceHolder" &gt;
  
  &lt;LayoutTemplate&gt;
          &lt;div class="table-responsive"&gt;
              &lt;table class="table"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;                            
                          &lt;th&gt;Last Name&lt;/th&gt;
                          &lt;th&gt;First Name&lt;/th&gt;
                          &lt;th&gt;UserName&lt;/th&gt;
                         &lt;th&gt;Approve User&lt;/th&gt;
  </code></pre>
  
  <p>
              </p>
  
  <pre><code>            &lt;td&gt;&lt;%# Item.LastName %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%# Item.FirstName %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%# Item.UserName %&gt;&lt;/td&gt;
              &lt;td&gt; &lt;asp:CheckBox ID="cbApproved" runat="server" AutoPostBack="true" OnCheckedChanged="Approve_Click" /&gt; &lt;/td&gt;
  </code></pre>
  
  <p><strong>c#</strong>:</p>
  
  <pre><code>protected void Approve_Click(object sender, EventArgs e)
      {
          foreach (ListViewItem item in lstUsers.Items)
          {
              if ((item.FindControl("cbApproved") as CheckBox).Checked == true)
              {
                  System.Diagnostics.Debug.WriteLine("it was checked!");
  </code></pre>
  
  <p>I've tried:</p>
  
  <ul>
  <li>item.ColumnName   -- but get error <em>ListView does not contain a
  definition for ''</em> </li>
  <li>item.DataItem  -- the output displays what looks
  like an object as a whole
  <em>(System.Web.UI.WebControls.ListViewDataItem)</em> </li>
  <li>item.DataItem.ColumnName
  -- but get error <em>Object does not contain a definition for ''</em></li>
  </ul>
  
  <p>Do the column values im looking to update in SQL have to be displayed on the ASPX page?</p>
  
  <p>I looked through:</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/bb398790.aspx#ModifyingDataUsingTheListViewControl" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/bb398790.aspx#ModifyingDataUsingTheListViewControl</a></p>
  
  <p><a href="https://stackoverflow.com/questions/19192207/asp-net-checkboxlist-to-update-a-sqldatasource">Asp.Net CheckBoxList to update a SqlDataSource</a></p>