I have a grid and in the grid I have two Item Template columns - Checkbox 1 and Checkbox 2.
I want to disable the whole Checkbox 1 column based on if a user is an admin or general user.
So say, if a user is an 'admin', I want both columns to be enabled and user can check/uncheck both the columns.
But, if a user is 'general user', I want to disable 'Checkbox1', so that user can only check/uncheck Checkbox 2. But can see values for 'Checkbox 1' column and can't edit it or make changes.
Presently, I am achieving this behavior as below-
protected void grdchkbox_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chkbox1 = (e.Row.FindControl("Checkbox1") as CheckBox);
if (IsGeneralUser(empid))
{
chkbox1.Enabled = false;
}
}
}
The problem with this is the page load time.
It is checking for user's role everytime a row is bound which means making db calls at each row bound.
Also, it's disabling a checkbox for each row separately.
Is there a way, I can disable the whole checkbox 1 column in one go?
Aucun commentaire:
Enregistrer un commentaire