---
title: "How can I access a ButtonFields text"  
description: "How can I access a ButtonFields text"  
author: "Anonymous User"  
published: 2014-08-26  
updated: 2014-08-26  
canonical: https://www.mindstick.com/forum/2140/how-can-i-access-a-buttonfields-text  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# How can I access a ButtonFields text

I'm trying to [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) text from a ButtonField(databound), but I can't get the text if I refer to it as a TableCell. What can I do to get its text?

<asp:[GridView](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) ID="gvClass" runat="server" [CssClass](https://www.mindstick.com/forum/12787/how-to-get-access-to-cssclass-property-for-server-element-isn-t-webcontrol-in-asp-dot-net)="grid" HeaderStyle-Font-Bold="true" Width="100%" OnSelectedIndexChanged="gvClass_SelectedIndexChanged" DataKeyNames="ClassID" AutoGenerateColumns="False" OnPageIndexChanging="gvClass_PageIndexChanging">

<HeaderStyle Font-Bold="True" />

<Columns>

<asp:ButtonField DataTextField="ClassID" HeaderText="Class ID" CommandName="Select" />

<asp:[BoundField](https://www.mindstick.com/forum/12737/get-the-value-of-a-boundfield-from-a-detailsview) DataField="CourseName" HeaderText="Course Name" />

<asp:BoundField DataField="WarehouseName" DataFormatString="[Warehouse](https://www.mindstick.com/blog/74142/technology-in-the-modern-warehouse-and-how-to-make-the-most-of-it)" HeaderText="Warehouse" />

<asp:BoundField DataField="TrainerNames" HeaderText="Trainer(s)" />

<asp:BoundField DataField="StartTime" HeaderText="Start Time" />

<asp:BoundField DataField="[Duration](https://answers.mindstick.com/qa/45301/what-is-a-short-duration-discussion)" HeaderText="Duration" />

<asp:BoundField DataField="Course Category" HeaderText="Course Category" />

<asp:BoundField DataField="Comment" HeaderText="Comment" />

</Columns>

<EmptyDataTemplate>

<span class="italic grey">No Record Found</span>

</EmptyDataTemplate>

</asp:GridView>

Code-behind:

[foreach](https://www.mindstick.com/forum/33870/how-parallel-foreach-works-internally) (GridViewRow gvr in gvClass.Rows)

{

foreach (TableCell tc in gvr.Cells)

{

stringToAppend = tc.Text;

sb.Append(PRTL_UtilityPackage.FormatHtmlCharacters(stringToAppend) + " \t");

}

sb.Append("\\n");

}

The foreach (TableCell tc in gvr.Cells) [comes up](https://answers.mindstick.com/qa/45369/if-you-search-worst-bollywood-actor-on-google-guess-whose-name-comes-up) with an [empty string](https://www.mindstick.com/forum/12697/json-stringify-is-sending-empty-string) when looking at the ButtonField.

## Replies

### Reply by Sumit Kesarwani

Hi Ashish, \

You can still use the tablecell method:

```
protected void myGridView_DataBound(object sender, GridViewRowEventArgs e){    if (e.Row.RowType == DataControlRowType.DataRow)    {        // You may have to play with the index of the control        // I have found that often a GridView will place a        // Literal control as Control[0] and the LinkButton        // as Control[1]. Once you find the index, it won't        // change.        LinkButton btn = (LinkButton)e.Row.Cells[0].Controls[1];        string text = btn.Text;    }}
```


---

Original Source: https://www.mindstick.com/forum/2140/how-can-i-access-a-buttonfields-text

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
