vis10: I think you're right on target here. The DataKeys collection is a collection of Primary Field values, therefore, unique, and can be used directly from the DataKeys collection to identify a record in SQL for editing, updating or general querying.
Here's an example of an aspx page where items are edited, and the updated, in a DataGrid using the DataKeyField. An EditCommandColumn is added to the datagrid and the Update and Cancel command events introduced.
The Grid conists of ProductID (Key field), ProductName, Price and the EditCommandColumn which begins with a hyperlink "Edit" heading, changing to Update & Cancel when Edit is selected.
<%@ Import Namespace="System.Data.SqlCient"%>
<Script Runat="Server">
Dim conNorthwind As SqlConnection
Dim cmdSql As SqlCommand
Dim strSql As String
Sub Page_Load
...connection string
If No IsPostBack Then
BindDataGrid
End If
End Sub
Sub BindDataGrid
cmdSql = New SqlCommand("Select * From Product", conNorthwind)
conNorthwind.Open()
dgrdProducts.DataSource=cmdSql.ExecuteReader()
dgrdProducts.DataBind()
conNorthwind.Close()
End Sub
Sub dgrdProducts_EditComman d(s As Object, e As DataGridCommandEventArgs)
dgrdProducts.EditItemIndex = e.Item.ItemIndex
BindDataGrid
End Sub
Sub dgrdProducts_UpdateCommand(s As Object, e As DataGridCommandEventArgs)
Dim intProductID As Integer
Dim txtProductName As Textbox
Dim txtUnitPrice As TextBox
Dim StrPRoductName As STring
Dim decUnitPrice As Decimal
intProductID = dgrdProducts.DataKeys(e.Item.ItemIndex)
txtProductName = e.Item.Cells(1).Controls(0)
txtUnitPrice = e.Item.Cells(2).Controls(0)
strProductName = txtProductName.Text
decUnitPrice = txtUnitPrice.Text
strSql = "Update Products Set ProcuctName=@ProductName, "_
& "UnitePrice=@UnitPrice Where ProductID=@ProductID"
cmdSql=New SqlCommand(strSql, conNorthwind)
cmdSql.Parameters.Add("@ProductName", strProductName)
cmdSql.Parameters.Add("@UnitPrice", decUnitPrice)
cmdSql.Parameters.Add("@ProductID, inProductID)
conNorthwind.Open()
cmdSql.ExecuteNonQuery()
conNorthwind.Close()
dgrdProducts.EditItemIndex = -1
BindDataGrid
End Sub
Sub dgrdProducts_CancelCommand(s As Objecdt, e As DataGridCommandEventArgs)
dgrdProducts.EditItemIndex = -1
BindDataGrid
End Sub
</script>
<html>
<head><title>DataGridEditProducts.aspx</title></head>
<body>
<form Runat="server">
<asp

ataGrid
ID="dgrdProducts"
OnEditCommand="dgrdProducts_EditCommand"
OnUpdateCommand="dgrdProducts_UpdateCommand"
OnCancelCommand="dgrdProducts_CancelCommand"
DataKeyField = "ProductID"
...
Runat="Server">
<Columns>
<asp:BoundColumn
HeaderText="Product ID"
DataField="ProductID"
/>
<asp:BoundColumn
HeaderText="Product Name"
DataField="ProductName"
/>
<asp:BoundColumn
HeaderText="Price"
DataField="UnitPrice"
DataFormatString="{0:c}" />
<asp:EditCommandColumn
EditText = "Edit!"
UpdateText = "Update!"
CancelText = "Cancel!"
</Columns>
</asp

ataGrid>
</form>
</body>
</html>
...so a good set of questions. I'l like everyone else here, learning -- so I think the DataKeysCollection, it seems, is a useful tool when a Primary Key field is involved in databinding -- no telling how much you can accomplish with it. And to answer your question, yes, the "value" of the Primary Key field is what is being checked against the rows bound to the grid or list.