[asp.net]如何gridview跑迴圈取得key值

  • 1865
  • 0

摘要:[asp.net]如何gridview跑迴圈取得key值


 For i As Integer = 0 To gvMain.Rows.Count - 1                
                Dim gvr As GridViewRow = gvMain.Rows(i)
                If gvr.RowType = DataControlRowType.DataRow Then
                    '如果是資料列的話
                    Dim chk As CheckBox = CType(gvMain.Rows(i).FindControl("chkCheck"), CheckBox) '檢查是否打勾
                    If chk.Checked = True Then
                        '打勾的就刪除
                        'gvMain.SelectedIndex = i
                        Dim dr() As DataRow = dt.Select(" mbrno= " & gvMain.DataKeys(i).Values("mbrno"))
                        dt.Rows.Remove(dr(0))
                    End If
                End If
            Next