how to find a command field control in the gridview.
in a method not in the row data bound.
so far i have used this coding but i cant find the control.
<asp:CommandField ButtonType="Image" ShowEditButton="True
HeaderText="Enter Leave"
EditImageUrl="~/IMAGES/edit-icon.gif">
<ItemStyle HorizontalAlign="Center" />
</asp:CommandField>
source code:
ImageButton edit = (ImageButton)EmployeeDetails.FindControl("Image");
edit.Enabled = false;
You can disable column itself with,
from code behind pages.
Or you can use ItemTemplate instead of CommandField,
And at code behind you can iterate through rows of GridView and disable each LinkButton.
First Edit :
I tried my second solution and it works. However, make sure your
GridViewis filled before you useforeach. Otherwise,GridView.Rows.Countwould probably be 0.Second Edit :
This works for
CommandFieldtoo. Replace 0 with the location ofCommandFieldin yourGridView.