Disabling Edit buttons in gridview

hello all,

I'm using the code below to disable the "delete" and "status" buttons while in edit mode. The problem I'm facing is that it only disables the "delete" and "status" button of the row which is in edit mode. The "delete" and "status" buttons for the rest of the rows are still visible. I want to disable them as well.

Any tips or idea would be appreciated
            gvUserLevel.EditIndex = e.NewEditIndex;
            Button btn = (Button)gvUserLevel.Rows[e.NewEditIndex].FindControl("btnDelete");
            btn.Enabled = false;
            Button btn1 = (Button)gvUserLevel.Rows[e.NewEditIndex].FindControl("btnStatus");
            btn1.Enabled = false;
            TextBox txtUserLevel = (TextBox)gvUserLevel.Rows[e.NewEditIndex].FindControl("EditUserlevelName");
            txtUserLevel.Text = txtUserLevel.Text.Trim();

Open in new window

Who is Participating?
foreach (GridViewRow row in gvUserLevel.Rows)
            ((Button)row.FindControl("btnDelete")).Enabled = false;
            ((Button)row.FindControl("btnStatus")).Enabled = false;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.