Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim gv As GridViewRow Dim sid As String = Session("name") For Each gv In GridView1.Rows Dim cb As CheckBox = gv.FindControl("kb") If cb.Checked = True Then Dim id As String = GridView1.DataKeys(gv.RowIndex).ToString Dim Sel As New QueryDB Dim dt As DataTable = Sel.kcm(id) Dim cname As String = dt.Rows(0)("CourseName").ToString Sel.Addxk(cname, sid) End If Next MsgBox("选课成功!", , "提示") End Sub