|
Because you did not call the Bind () method at the end of the loop, if you select something other than the first line, the following CheckBox selections are all ineffective. You only need to put the Bind () call after the For loop and it is OK , as follows.
Dim i As Integer
Dim ChBox As CheckBox
Dim label1 As Label
For i = 0 To DataGrid1.Items.Count-1
ChBox = CType (DataGrid1.Items (i) .Cells (0) .FindControl ("CheckBox1"), CheckBox)
label1 = CType (DataGrid1.Items (1) .FindControl ("label1"), Label)
If ChBox.Checked = True Then
Dim conn As New SqlConnection
conn.ConnectionString = "server = 127.0.0.1; uid = sa; pwd =; database = netexam"
conn.Open ()
Dim sql As String
sql = "delete from question where id = '" + label1.Text + "'"
Dim cmd As New SqlCommand (sql, conn)
cmd.ExecuteNonQuery ()
End If
Next
bind () |
|