Results 1 to 2 of 2

Thread: get the text of buttoncolumn displayed as link

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    37

    get the text of buttoncolumn displayed as link

    Hi,
    I have a datagrid that displays the customer information. I have the customer id as a buttoncolumn and ButtonType=LinkButton. I want the value of the customer id when I click on the customer id link in the datagrid
    Can someone help...

    Thanks in advance

  2. #2
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Re: get the text of buttoncolumn displayed as link

    You need to set the datakeyfield of the datagrid to the Customer ID. When you click on an item in the grid, you can access the datakeyfield of that item in the code behind:

    In your datagrid put:

    Code:
    OnItemCommand="View_Customer" DataKeyField="CustomerID"
    In your customer id button column put:

    Code:
    <asp:ButtonColumn DataTextField="CustomerID" CommandName="Select" HeaderText="Customer ID"></asp:ButtonColumn>
    In your code behind you need:

    VB Code:
    1. Public Sub View_Item(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
    2.         'get customer id and redirect
    3.         Dim strCustomerID As String
    4.  
    5.         If Not e.Item.ItemIndex = -1 Then
    6.             'gets the value (customer id) of the key column for the selected row
    7.             strCustomerID = CType(dgrItems.DataKeys(e.Item.ItemIndex), String)
    8.         End If
    9.  
    10.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width