You can hide the Update, Edit, and Delete buttons in GridViews. To do this:
-
In the .NET editor, override the
OnPreLoad
method, and add aRowDataBound
event to the GridView using the following code:protected override void OnPreLoad(EventArgs e) { base.OnPreLoad(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 }
-
In the code example below, the control fields (
edit
,delete
, andupdate
) are in the fourth column (index 3). To hide the Edit button in theRowDataBound
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; } } } } }
-
To hide a different button, put the appropriate text in the
if
clause. For example:if(b.Text == "Delete")` or `if b.Text == "Update"