Reputation: 1729
I am working with an old web application developed in VB.NET 1.1 framework. I am having an issue with checkboxes.
I have the following code for my checkbox:
<asp:TemplateColumn HeaderText="Reviewed">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:checkbox ID="chkAppRev" Runat="server"
OnCheckedChanged="onCheckChange" AutoPostBack="True" />
</ItemTemplate>
</asp:TemplateColumn>
and this for my OnCheckChanged
event:
Public Sub onCheckChange(ByVal sender As Object, ByVal e As EventArgs)
Dim strSQL As String = String.Empty
Dim inbox As CheckBox = CType(sender, CheckBox)
Dim dgItem As DataGridItem = CType(inbox.NamingContainer, DataGridItem)
Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationSettings.AppSettings("CONNECTIONSTRING"))
Try
'--update checkbox field on record in database
conn.Open()
If inbox.Checked = True Then
strSQL = "Update AppUserJobs Set AppChecked=1 " & _
"Where AppUserId=" & Convert.ToInt32(dgItem.Cells(9).Text) &
" and JobId=" & Convert.ToInt32(dgItem.Cells(10).Text)
Else
strSQL = "Update AppUser Set AppChecked=0 " & _
"Where AppUserId=" & Convert.ToInt32(dgItem.Cells(9).Text) &
" and JobId=" & Convert.ToInt32(dgItem.Cells(10).Text)
End If
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(strSQL, conn)
Dim intRec As Integer = cmd.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
Finally
If (conn.State = ConnectionState.Open) Then
conn.Close()
End If
End Try
BindData()
End Sub
This all works fine until I add another check box in the asp code and another oncheckchanged
method, it seems like it just skips over the query.
Does anyone have any ideas what I missed?
Upvotes: 0
Views: 1028
Reputation: 700332
You have a BIG NO-NO in the code: it is silently cathing an exception and throwing it away.
There is some kind of exception somewhere in the method, but as you throw away all information about it, there is no hint to what it is that goes wrong. It's probably some of the references that is null, but without any information that tells you which one, it's hard to spot the problem.
Remove this line so that the exception is not silently buried:
Catch ex As Exception
Alternatively put some code after it that actually handles the exception. In that case you should change the line so that you don't catch the base class Exception
but some more specific exception class like SqlException
.
With some information about where the exception occurs, it's possible to spot the problem.
Upvotes: 1
Reputation: 38842
Just to be sure, is there a typo in your code on just in the question?
oncheckchanged or oncheckchange
--
Also what do you mean by "I add another check box in the asp code and another oncheckchanged method"? Do you actually create another handler?
Upvotes: 0
Reputation: 36081
Did you ensure that you entered the Runat="server" and AutoPostBack="True" tags?
Upvotes: 0