摘要:[asp.net]迴圈取得grid裡面所有的欄位值(須設定datakey)
主要是針對grid裡面的asp:boundfield欄位取值
查詢的時候記得先把這些要取值的欄位設定為DatakeyName
如果是asp:boundfield以外的欄位,例如asp:checkbox
那也只要加上
Dim chk As CheckBox = CType(gvr.FindControl("chk"), CheckBox)
即可
For Each gvr As GridViewRow In gvMain.Rows
If gvr.RowType = DataControlRowType.DataRow Then
'Dim drv As DataRowView = CType(gvr.DataItem, DataRowView)
'這是取得grid裡面的checkbox
Dim chk As CheckBox = CType(gvr.FindControl("chk"), CheckBox)
If chk.Checked = True Then
'這是取得grid裡面的asp:bound的值,但是必須先在grid設定好datakeyname
Dim straaa As String = gvMain.DataKeys(gvr.RowIndex)("AvoSrc")
End If
End If
Next