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

Hiding Command Item Templates (Hyper Links) after reordering columns on server side

2 Answers 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Taiseer
Top achievements
Rank 1
Taiseer asked on 05 Nov 2009, 12:17 PM

Dear All,

I’m setting the visibility of the command item (Hyper Link)in the command item template (Add New Record) on the grid pre render event based on logged in user permissions.

The code used is shown below: 

foreach (GridItem Item in grdUsers.MasterTableView.GetItems(GridItemType.CommandItem))     
                {     
                    GridCommandItem CommandItem = (GridCommandItem)Item;     
                    LinkButton InitLinkButton = (LinkButton)CommandItem.FindControl(functionalitiesRow.ControlName);     
    
                    if (InitLinkButton != null)     
                    {     
                        InitLinkButton.Visible = false;     
                        break;     
                    }     
    
    
                } //End for each    
 


The problem is that when I do reordering for the column on the server side the code in grid pre render even is executed and the Hyper Link visibility is set to false but when the page appears the (Add New Record) hyper link is visible to the user and s/he can click on it.

This problem only appears on the reordering columns functionality.

I don’t want to reorder the column on client side, because am preserving the grid state and columns order for the logged in user.

Any suggests to my problem?

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 06 Nov 2009, 04:00 PM
Hello Tosser,

The button become visible due to the fact that RadGrid rebinds on it's PreRender event. Proper way of hiding the button should be on ItemCreated event as follow:
1.protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
2.{
3.    if (e.Item is GridCommandItem)
4.    {
5.        var item = e.Item as GridCommandItem;
6.        item.FindControl("InitInsertButton").Visible = false;
7.    }
8.}


Regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Taiseer
Top achievements
Rank 1
answered on 08 Nov 2009, 09:59 AM
Thanks. it works great!!
Tags
Grid
Asked by
Taiseer
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Taiseer
Top achievements
Rank 1
Share this question
or