Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Linkbutton in Grid
Message
De
03/09/2003 02:06:54
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
 
 
À
02/09/2003 09:48:37
Mindy Shingara
Central Susquehanna Intermediate Unit
Lewisburg, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
WebForms
Divers
Thread ID:
00825288
Message ID:
00825562
Vues:
18
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??
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform