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
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:
Public Sub View_Item(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
'get customer id and redirect
Dim strCustomerID As String
If Not e.Item.ItemIndex = -1 Then
'gets the value (customer id) of the key column for the selected row
strCustomerID = CType(dgrItems.DataKeys(e.Item.ItemIndex), String)
End If
End Sub