For Each dgitem In mydg.Items
            ck = CType(dgitem.Cells(0).FindControl("ck"), CheckBox)
          
Dim bSelected as Bollean
bSelected  =false
  If ck.Checked Then
                 dkey = mydg.DataKeys(dgitem.ItemIndex)
                 deldb(dkey)‘--删除数据
        '        dbind()’--涮新datagrid
'                Exit For
bSelected   =true
'            Else
 '               warn.showmsg(Me, "请选择要删除的记录!")
  '              Exit For
            End If
        NextIf   bSelected    Then
            dbind()
Else
     warn.showmsg(Me, "请选择要删除的记录!")
      
End If

解决方案 »

  1.   

    不能cell(0)啦Dim dgitem As DataGridItem
            Dim ck As CheckBox
            Dim dkey As String
            For Each dgitem In mydg.Items
                ck = CType(dgitem.FindControl("ck"), CheckBox)
                If ck.Checked Then
                    dkey = mydg.DataKeys(dgitem.ItemIndex)
                    deldb(dkey)‘--删除数据
                    dbind()’--涮新datagrid
                    Exit For
                Else
                    warn.showmsg(Me, "请选择要删除的记录!")
                    Exit For
                End If
            Next
      

  2.   

    OK 了。。 
    Dim dgitem As DataGridItem
            Dim ck As CheckBox
            Dim dkey As Integer        For Each dgitem In mydg.Items
                If dgitem.ItemType <> ListItemType.Header And dgitem.ItemType <> ListItemType.Footer And dgitem.ItemType <> ListItemType.Pager Then                ck = CType(dgitem.FindControl("ck"), CheckBox)
                    Dim boolstr As Boolean
                    boolstr = ck.Checked
                    If boolstr = True Then
                        dkey = mydg.DataKeys(dgitem.ItemIndex)
                        deldb(dkey)
                    Else
                        warn.showmsg(Me, "请选择要删除的记录!")
                    End If            End If
            Next
            dbind()