2017年3月26日 星期日

how to use multiple datakeys in gridview in asp.net

Using Multiple DataKeyNames (DataKeys) in ASP.Net GridView with examples
---
使用:
DataKeyNames="Id, Group"

取值:
Protected Sub GridView_Button_Click(sender As Object, e As EventArgs)
    'Determine the RowIndex of the Row whose Button was clicked.
    Dim rowIndex As Integer = TryCast(TryCast(sender, Button).NamingContainer, GridViewRow).RowIndex

    'Get the value of column from the DataKeys using the RowIndex.
    Dim id As Integer = Convert.ToInt32(GridView1.DataKeys(rowIndex).Values(0))
    Dim group As String = GridView1.DataKeys(rowIndex).Values(1).ToString()
End Sub

沒有留言:

張貼留言