Mindy,
To get at the PK of the row, you have to hook into OnItemCreated event of the DataGrid and store the primary key value in the CommandArgument of the link button.
In the HTML:
<asp:DataGrid id="myDataGrid"
OnItemCreated="DataGrid_ItemCreated"
DataKeyField="myPKColumn"
runat="server">
. . . </asp:DataGrid>
In the code-behind:
Sub DataGrid_ItemCreated(Sender As Object, e As DataGridItemEventArgs)
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
Dim myLinkButton As LinkButton
myLinkButton = e.Item.FindControl("btnLink")
myLinkButton.Attributes.Add("CommandArgument","" & DataItem.myPKColumn & "")
End Select
End Sub
Now you can use the CommandArgument property to reference the PK of the row that is clicked.
** Note: This code is modified from an example of processing a delete button, it may require some tweaking. The original code is at
http://www.aspalliance.com/aldotnet/examples/cd.aspx>I show particular accounts from a fox pro table in a column in my datagrid as a linkbutton. I can click the linkbutton and redirect my page and all works fine. However, I can't seem to get the value of the account that I click into a session variable to carry back to the page I'm redirecting to. How do I reference the particular cell within the grid that was clicked and what grid event to I use??