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..)
I'm working in vb.net creating an asp.net web application. I have an SqlDataSource and a GridView on my page:
<asp:SqlDataSource ID="msgUnread" runat="server"
ConnectionString="<%$ ConnectionStrings:edinsec %>"
SelectCommand="SELECT [msgdate], [email], [name], [message], [readit] FROM [messages]"
UpdateCommand="UPDATE messages SET readit = 'True' WHERE (msgid = @msgid)">
<UpdateParameters>
<asp:Parameter Name="msgid" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="unreadMessages" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataSourceID="msgUnread">
<RowStyle ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="msgdate" HeaderText="Date & time"
SortExpression="msgdate" />
<asp:BoundField DataField="email" HeaderText="Email"
SortExpression="email" />
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />
<asp:TemplateField HeaderText="Mark as read" SortExpression="readit">
<%--<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("readit") %>' OnCheckedChange="CheckBox1_CheckedChanged" />
</EditItemTemplate>--%>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("readit") %>' OnCheckChanged="CheckBox1_CheckedChanged" AutoPostBack="true"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
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).
Here's my CodeBehind:
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
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).
I'm pretty stumped. Can anyone help? Would be much appreciated :)