Sometimes we need to do invisible some particular column of a gridview for some cases.This can do as follows.
In below example admin can Only view column 2 and 21.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(user != "Admin")
{
if(e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[2].Visible=false;
e.Row.Cells[21].Visible=false;
}
else if(e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].Visible=false;
e.Row.Cells[21].Visible=false
}
}
}
Hello Rakesh
ReplyDeletewrite below line just above
bool isAllowedToEditJob = Convert.ToBoolean(Session["EditJob"]);
and replace line if(user != "Admin") with
if(isAllowedToEditJob == false)
your google profile
ReplyDeletei have one gridview.inside that gridview there is one CommandField as
ReplyDeleteShowEditButton="True" HeaderText="Edit"
and ItemTemplete
as Delete
now my condition is that we have saveral users.
some users has rights to edit or delete but some has not right to delete or edit.
so those users who has not rights to edit and delete job,should not view edit or delete button.
hello Arvind,
ReplyDeleteEdit is working perfectly but delete button is not working
hello
ReplyDeletewhat is the column index of this two field?
This comment has been removed by a blog administrator.
ReplyDeleteyes now its working
ReplyDeletegood'