Getting the text of the ButtonColumn  
Author Message
inBerlin





PostPosted: Thu Sep 08 09:50:01 CDT 2005 Top

ASP.Net >> Getting the text of the ButtonColumn

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.

Web Programming18  
 
 
john_teague





PostPosted: Thu Sep 08 09:50:01 CDT 2005 Top

ASP.Net >> Getting the text of the ButtonColumn Try casting as a LinkButton