title: VB.net - make Gridview checkbox update boolean field in database
body: <p>There are lots of questions about this but I've not been able to solve my problem using the answers to any of them (after many, many attempts..)</p>
  
  <p>I'm working in vb.net creating an asp.net web application. I have an SqlDataSource and a GridView on my page:</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="msgUnread" runat="server" 
   ConnectionString="&lt;%$ ConnectionStrings:edinsec %&gt;" 
  
   SelectCommand="SELECT [msgdate], [email], [name], [message], [readit] FROM [messages]" 
   UpdateCommand="UPDATE messages SET readit = 'True' WHERE (msgid = @msgid)"&gt;
         &lt;UpdateParameters&gt;
       &lt;asp:Parameter Name="msgid" /&gt;
   &lt;/UpdateParameters&gt;
     &lt;/asp:SqlDataSource&gt;
  
  
     &lt;asp:GridView ID="unreadMessages" runat="server" AutoGenerateColumns="False" 
   BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" 
   CellPadding="3" DataSourceID="msgUnread"&gt;
   &lt;RowStyle ForeColor="#000066" /&gt;
   &lt;Columns&gt;
       &lt;asp:BoundField DataField="msgdate" HeaderText="Date &amp;amp; time" 
           SortExpression="msgdate" /&gt;
       &lt;asp:BoundField DataField="email" HeaderText="Email" 
           SortExpression="email" /&gt;
       &lt;asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" /&gt;
                   &lt;asp:TemplateField HeaderText="Mark as read" SortExpression="readit"&gt;
           &lt;%--&lt;EditItemTemplate&gt;
               &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%# Bind("readit") %&gt;'  OnCheckedChange="CheckBox1_CheckedChanged"  /&gt;
           &lt;/EditItemTemplate&gt;--%&gt;
           &lt;ItemTemplate&gt;
               &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%# Bind("readit") %&gt;' OnCheckChanged="CheckBox1_CheckedChanged" AutoPostBack="true"/&gt;
           &lt;/ItemTemplate&gt;
       &lt;/asp:TemplateField&gt;
   &lt;/Columns&gt;
   &lt;FooterStyle BackColor="White" ForeColor="#000066" /&gt;
   &lt;PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /&gt;
   &lt;SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /&gt;
   &lt;HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /&gt;
     &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>The GridView is populated properly, with the checkboxes' values being properly displayed (the 'readit' field is a bit field, i.e. boolean). I'm trying to get the script to update the boolean value in the database when the checkbox is clicked. At the moment though I can't even get the script to react to a click (not even a MsgBox).</p>
  
  <p>Here's my CodeBehind:</p>
  
  <pre><code>Public Partial Class enqur
  Inherits System.Web.UI.Page
  WithEvents CheckBox1 As CheckBox
  
  
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  
  End Sub
  
  Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
      MsgBox("test")
  End Sub
  
  End Class
  </code></pre>
  
  <p>As you can see I was playing with WithEvents but that didn't seem to help. In the above code all I was trying to get was some kind of reaction to the clicking of a checkbox - but nothing happens (no errors, either).</p>
  
  <p>I'm pretty stumped. Can anyone help? Would be much appreciated :)</p>