Form Designer: How to hide the update, edit, or delete buttons in a GridView

You can hide the Update, Edit, and Delete buttons in GridViews. To do this:

  1. In the .NET editor, override the OnPreLoad method, and add a RowDataBound event to the GridView using the following code:

    protected override void OnPreLoad(EventArgs e)
            // To hide a control field button
            REQUEST_GRIDVIEW.RowDataBound += new GridViewRowEventHandler(Gridview_RowDataBound);
    private void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
            //Code to hide control field buttons
  2. In the code example below, the control fields (edit, delete, and update) are in the fourth column (index 3). To hide the Edit button in the RowDataBound method, add the following code:

    private void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)
                //In this example, the controls are in the fourth index (index == 3)
                foreach (Control c in e.Row.Cells[3].Controls){
                    if (c is Button){
                        Button b = (Button)c;
                        if (b.Text == "Edit"){
                            b.Visible = false;
  3. To hide a different button, put the appropriate text in the if clause. For example:

    if(b.Text == "Delete")` or `if b.Text == "Update"

Hi @eddy.daouk,

I am trying to hide the cancel button, when the row is in edit mode.
I am trying to minimize the number of clicks a user needs to do on the grid.
Is there a way we can make the cancel button hidden.

I tried using the suggested scripts above however, the button still appears.

thanks Clay

Hi @clayton,

There are two things that need to be changed in the Gridview_RowDataBound method above:

1- First, make sure that the code contains the correct index:
If the button is on the second column, the index is 1, so the code will be:
foreach (Control c in e.Row.Cells[1].Controls){...}
If you indicate the wrong index, the button will not be found. Hence, the button will still appear.

2- Finally make sure that the label of the cancel button is well written in the code (Case sensitive):
if (b.Text == "Cancel"){...}

Hope this helps.


Hi @eddy.daouk.

It worked! Awesome.

Thanks Clay

1 Like

Check this Add, Edit, Delete…GridView example