This documentation is archived and is not being maintained.

ButtonField.Text Property

Gets or sets the static caption that is displayed for each button in the ButtonField object.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public virtual string Text { get; set; }

Property Value

Type: System.String
The caption displayed for each button in the ButtonField. The default is an empty string ("").

When the ButtonType property of a ButtonField object is set to the Button or Link value, use the Text property to display static text for the caption of the buttons in the ButtonField. Each button shares the same caption.

Instead of using the Text property to display static text in a ButtonField object, you can use the DataTextField property to bind the ButtonField to a field in a data source. The values of the field are then displayed as the caption of the buttons.


If the DataTextField and Text properties are both set, the DataTextField property takes precedence.

The value of this property is stored in view state.

The value of this property, when set, can be saved automatically to a resource file by using a designer tool. For more information, see LocalizableAttribute and ASP.NET Globalization and Localization.

The following code example demonstrates how to use the Text property to specify the caption to display for each button in a ButtonField object.

<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)

    // If multiple ButtonField column fields are used, use the
    // CommandName property to determine which button was clicked.

      // Convert the row index stored in the CommandArgument
      // property to an Integer.
      int index = Convert.ToInt32(e.CommandArgument);    

      // Get the last name of the selected author from the appropriate
      // cell in the GridView control.
      GridViewRow selectedRow = CustomersGridView.Rows[index];
      TableCell contactName = selectedRow.Cells[1];
      string contact = contactName.Text;  

      // Display the selected author.
      Message.Text = "You selected " + contact + ".";




<html xmlns="" >
  <head runat="server">
    <title>ButtonField Example</title>
    <form id="form1" runat="server">

      <h3>ButtonField Example</h3>

      <asp:label id="Message"

      <!-- Populate the Columns collection declaratively. -->
      <asp:gridview id="CustomersGridView" 


          <asp:buttonfield buttontype="Button" 
            headertext="Select Customer" 
          <asp:boundfield datafield="CompanyName" 
            headertext="Company Name"/>
          <asp:boundfield datafield="ContactName" 
            headertext="Contact Name"/>



        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Northwind sample database.                   -->
        <asp:sqldatasource id="CustomersSqlDataSource"  
          selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.