Getting the text of the ButtonColumn

  • Thread starter Thread starter Sathyaish
  • Start date Start date
S

Sathyaish

How do you get the text of a ButtonColumn control column in a datagrid?
As an example, I tried this little snippet on a test project, but it
returns a null string.


Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dg.ItemCommand
If Not e.Item Is Nothing Then
lblMessage.Text = "You clicked " & e.Item.Cells(1).Text &
"."
End If
End Sub


where the column clicked is of type ButtonColumn and it is the second
column (index 1) in the row.

<asp:ButtonColumn DataTextField="Full Name" HeaderText="Full
Name"></asp:ButtonColumn>

I also tried:

Dim lbl As HyperLink = CType(e.Item.Cells(1).Controls(0), HyperLink)
lblMessage.Text = "You clicked " & lbl.Text & "."

but it said that the specified cast is not valid.
 
Back
Top