Last post Jul 09, 2019 04:46 PM by oneillj
Jul 07, 2019 03:07 AM|oneillj|LINK
I have a utility I used on one form to disable all the select and delete linkbuttons on a gridview after the select has been pressed by the user. The data for that row gets transferred onto a form for editing. This is so the user can't delete or select a
record while an edit is on progress. The gridview has a select on the first column and a delete on the last column. Everything seems to work fine. But I have a gridview on another form that has a Edit, Update, Cancel on the first column and a delete on the
last column. The first column is template so I can place a break tag between the update and cancel buttons to get them on two lines. Everything is done on the gridview itself. No form. The problem is the control index of the last column where the delete linkbutton
is. I keep getting an index out of range error even though I have the column indexes right. The one that works is being called of a method that takes commands from both the gridview and the form where the on that doesn't is being called of the RowEditing method
of the gridview. So, why are my control indexes off? It seems that they should be the same. The only thing I can think of is the one that has problems is the gridview that has the Edit, Update, Cancel. But still, the last column only has one control in it.
Why would I have problems?
On a side note, no matter how much I try, I still can't get the Update Cancel styles to maintain the one for that column prior to editing.
public static void DisableGridviewRows(GridView gv, int selectCol, int deleteCol)
TableCell cell = new TableCell();
foreach (GridViewRow gvr in gv.Rows)
if (gvr.RowType == DataControlRowType.DataRow)
if (gvr.RowIndex == gv.EditIndex)
gv.Columns[selectCol].ControlStyle.CssClass = "GvCmd";
//Change style to grayed
gv.Columns[selectCol].ControlStyle.CssClass = "GvCmdDisabled";
gv.Columns[deleteCol].ControlStyle.CssClass = "GvCmdDisabled";
//Get first column where command is
cell = gvr.Cells[selectCol];
LinkButton lbSelect = cell.Controls as LinkButton;
lbSelect.Enabled = false;
//Disable delete buttons
cell = gvr.Cells[deleteCol];
LinkButton lbDelete = cell.Controls as LinkButton;
lbDelete.Enabled = false;
Jul 07, 2019 11:31 PM|KathyW|LINK
Since none of us know what your gridview looks like, or what you are passing to your DisableGridviewRows function, all we can say is that... your control's index is out of range. Are there two controls in whichever cell is throwing the error? Debug what
you are doing.
Jul 08, 2019 05:28 AM|samwu|LINK
Based on your description and code, I can't reproduce your problem.
I suggest you debug and check the length of the array or the data table indexes and then see whether you are deleting the correct index or not.
If the problem has not been resolved, please post your aspx,aspx.cs codes and more details information about your requirement.
Jul 09, 2019 04:46 PM|oneillj|LINK
I meant to get back on this earlier. I found out that on one of the controls, I had a template field in that column which was throwing off the other one. So, I made the structure identical and it fixed the problem.