This is a migrated thread and some comments may be shown as answers.

Hiding CommandItem on Grid

6 Answers 315 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yunuen Sanchez
Top achievements
Rank 1
Yunuen Sanchez asked on 03 Mar 2012, 09:58 PM
Hello,

I'm trying to hide the command item section on a grid based on user preferences, something like this:

if(user has no access)
{
    grid.AllowAutomaticInserts = false;
    grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
    //also I perform some code to hide columns
}

I use PreRender event to execute it. Hiding columns works fine but I still get the CommandItem section on the top of the grid. However, if I click on "Add new record" link, that section disappears after postback, showing the grid the way I want it. This is fine, I mean the user can't add items, but I don't want him to see the option as available.

If I call Rebind() after the above code is executed, the command section goes away. That's fine but the DataBind event is called twice, a behavior I don't want.

Am using the right event (PreRender) to execute the code? 

One more thing, my grid is inside a RadDock.

Thanks

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Mar 2012, 05:18 AM
Hello,

Try the following code.
C#:
protected void grid_PreRender(object sender, EventArgs e)
{
   GridCommandItem cmd = (GridCommandItem)grid.MasterTableView.GetItems(GridItemType.CommandItem)[0];
   cmd.Visible = false;
}

-Shinu.
0
Yunuen Sanchez
Top achievements
Rank 1
answered on 05 Mar 2012, 04:28 PM
That did the trick!

Could you explain me what is the difference between this option and the one I was trying?

Thanks a lot Shinu!
0
Huang
Top achievements
Rank 1
answered on 04 Apr 2012, 03:46 PM
I also found setting CommandItemDisplay has no effect. (2011q2)
0
Richard
Top achievements
Rank 1
answered on 06 Apr 2012, 03:37 PM
Huang:

Here's what I found when using the most current RadGrid 2012.1.215.40 build.

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    // This works when using RadGrid 2012.1.215.40
    GridCommandItem cmd = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
    cmd.Visible = false;
 
    // This does not hide the Command Item Bar when using RadGrid 2012.1.215.40
    RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
 
}

Hope this helps!
0
Huang
Top achievements
Rank 1
answered on 09 Apr 2012, 10:45 AM
Thanks! I got it. CommandItemDisplay property must be set readonly, because it leads us to a wrong way:)
0
Ching Luo
Top achievements
Rank 1
answered on 17 Oct 2012, 10:22 PM
after dgGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None, try to run dgGrid.Rebind() to make it effective
Tags
Grid
Asked by
Yunuen Sanchez
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Yunuen Sanchez
Top achievements
Rank 1
Huang
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Ching Luo
Top achievements
Rank 1
Share this question
or