ButtonType Enumeration


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Specifies the different types of buttons that can be rendered in a Web Forms page.

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

public enum ButtonType

Member nameDescription

A command button.


A button that displays an image.


A hyperlink-style button.

The ButtonType enumeration is used to represent the different types of buttons (such as command button, image button, link button, and so on) that can be rendered on an ASP.NET page. It is commonly used by properties such as the ButtonType property of the ButtonFieldBase class to indicate which button type is being used by the parent control.

The following example demonstrates how to use the ButtonType enumeration to specify that link buttons are displayed in a ButtonField field column of a GridView control. The ButtonType property of a ButtonField object is declaratively set to ButtonType.Link.

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

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

  void AuthorsGridView_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 = AuthorsGridView.Rows[index];
      TableCell lastNameCell = selectedRow.Cells[1];
      string lastName = lastNameCell.Text;  

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



  void AuthorsGridView_RowCreated(Object sender, GridViewRowEventArgs e)

    // The GridViewCommandEventArgs class does not contain a 
    // property that indicates which row's command button was
    // clicked. To identify which row contains the button 
    // clicked, use the button's CommandArgument property by 
    // setting it to the row's index.
    if(e.Row.RowType == DataControlRowType.DataRow)

      // Retrieve the button control from the first column.
      // Because the ButtonType property of the column field
      // is set to ButtonType.Link, the button control must be
      // cast to a LinkButton. If you specify a different button
      // type, you must cast the button control to the appropriate
      // button type.
      LinkButton selectButton = (LinkButton)e.Row.Cells[0].Controls[0];

      // Set the LinkButton's CommandArgument property with the
      // row's index.
      selectButton.CommandArgument = e.Row.RowIndex.ToString();




<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ButtonType Example</title>
    <form id="form1" runat="server">

      <h3>ButtonType Example</h3>

      <asp:label id="Message"

      <!-- Populate the Fields collection declaratively. -->
      <asp:gridview id="AuthorsGridView" 


          <asp:buttonfield buttontype="Link" commandname="Select" text="Select"/>
          <asp:boundfield datafield="au_lname" headertext="au_lname"/>
          <asp:boundfield datafield="au_fname" headertext="au_fname"/>



      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"


.NET Framework
Available since 2.0
Return to top