This question morphed from a previous one here.
It seems that the problem is actually this failure to recognize checkboxes as such - whether there's really a problem with updating the database once this conundrum is solved remains to be seen.
So here's the code:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connStr As String = "SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=entenhausen;PWD=pondscum"
Dim upd8DML As String = "UPDATE CustomerCategoryLog SET Category = 'Exploding' WHERE Unit = @Unit And MemberNo = @MemberNo AND Custno = @CustNo"
Dim coName As String
Dim argVals(2) As String
Dim _Unit As String
Dim _MemberNo As String
Dim _CustNo As String
Dim curCheckboxIDVal As String
Label2.Text="label 2 text from button1_click"
LabelDebug.Text="label debug text from button1_click"
For Each cntrl As Control In Me.Controls
Label2.Text="label 2 text from foreach"
If TypeOf cntrl Is CheckBox Then
Label2.Text="label 2 text from is checkbox"
If DirectCast(cntrl, CheckBox).Checked = True Then
Label2.Text="label 2 text from checked"
curCheckboxIDVal = CStr(DirectCast(cntrl, CheckBox).ID)
coName = GetLabelTextForID(curCheckboxIDVal)
argVals = GetArgValsForCompanyName(coName)
_Unit = argVals(0)
_MemberNo = argVals(1)
_CustNo = argVals(2)
Label2.Text=_Unit
LabelDebug.Text=_MemberNo
Using conn As New SqlConnection(connStr), _
cmd As New SqlCommand(upd8DML, conn)
cmd.Parameters.Add("@Unit", SqlDbType.VarChar, 50).Value = _Unit
cmd.Parameters.Add("@MemberNo", SqlDbType.VarChar, 50).Value = _MemberNo
cmd.Parameters.Add("@CustNo", SqlDbType.VarChar, 50).Value = _CustNo
conn.Open
cmd.ExecuteScalar()
End Using
End If
End If
Next
End Sub
I am updating Label2.Text to see how far the code gets - and it only gets to the "foreach" - this is the last value of Label2.Text: "label 2 text from foreach"
So this line:
If TypeOf cntrl Is CheckBox Then
...fails to equate to true.
Yet, not only do I have many dynamically-created Checkboxes on the form when the button is clicked, there is also one that I dropped there at design-time. NONE of these checkboxes are seen as checkboxes, obviously.
Why not? Why is the type of the checkbox control not evaluating to CheckBox?
NOTE: When I prepend "the whole shebang" like so:
System.Web.UI.WebControls.CheckBox
...it makes no difference; in fact, it grays out the "System.Web.UI.WebControls." portion.
Aucun commentaire:
Enregistrer un commentaire