I am trying to toggle whether or not a CommandField.ShowEditButton is true or false with the following code:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
clsEmployee employee = (clsEmployee)e.Row.DataItem;
CommandField cmdField = (CommandField)((DataControlFieldCell)e.Row.Cells[0]).ContainingField;
cmdField.ShowEditButton = _currentUser.FullName.Equals(employee.FullName);
}
}
It works, but on the proceeding line; not the current one. If I am logged in as John Smith, this happens:
+------+-------------------------------------+
| | John Smith |
+------+-------------------------------------+
| Edit | Jane Doe |
+------+-------------------------------------+
I know I am on the right row, because this works (ShowEditButton is always true for the CommandField):
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
clsEmployee employee = (clsEmployee)e.Row.DataItem;
e.Row.Cells[0].Enabled = _currentUser.FullName.Equals(employee.FullName);
}
}
When I am logged in as John Smith, I get:
+------+-------------------------------------+
| Edit | John Smith |
+------+-------------------------------------+
| Edit | Jane Doe |
+------+-------------------------------------+
with the John Smith Edit being enabled and the Jane Doe one being disabled.
How can I get the first method to work?