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

how to hide button links insert, edit and add a new records from the RadGrid

3 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Syed
Top achievements
Rank 1
Syed asked on 06 May 2009, 11:19 AM
Hi,

On the web page RadGrid is able to perform insert,delete and  Add a new records. I am able to view insert,edit and add a new record button links.
 
Sometimes i am able to show these button links for some users and sometimes i want to hide these button link from the grid.

Please tell me how to hide these button links.

Thanks.

Regards
Arshad

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 06 May 2009, 01:12 PM
Hi Syed,

Try out the following code snippet for hiding CommandItem and EditColumn based on condition.

CS:
 
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    if(test) //Condition 
    { 
        RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; 
        RadGrid1.Rebind(); 
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        { 
            if (col.UniqueName == "AutoGeneratedEditColumn")  // If it is AutoGenerated, otherwise check with the column unique name 
            { 
                col.Visible = false
            } 
        } 
    } 

Thanks,
Shinu.
0
Accepted
ManniAT
Top achievements
Rank 2
answered on 06 May 2009, 02:50 PM
A have a similar case - Admins are allowed to edit / insert in the MasterTable - other roles not.
I do it like this:
            <Columns> 
                <telerik:GridEditCommandColumn UniqueName="MEditColumn" ButtonType="ImageButton" ItemStyle-Width="25px" HeaderStyle-Width="25px" Visible="false" /> 
                <telerik:GridBoundColumn DataField="ContentID" DataType="System.Int32" HeaderText="ID" 
Notice the UniqueName on the GridEditCommandColumn!
In code behind I allow the things - if the user is an admin (rgContent is the ID of my grid):
protected void Page_Load(object sender, EventArgs e) {  
    if (Roles.IsUserInRole("Admins")) {  
        rgContent.MasterTableView.Columns.FindByUniqueName("MEditColumn").Visible = true;  
        rgContent.MasterTableView.AllowAutomaticUpdates = true;  
        rgContent.MasterTableView.AllowAutomaticInserts = true;  
        rgContent.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;  
    }  
}  
 

HTH

Manfred
0
Syed
Top achievements
Rank 1
answered on 06 May 2009, 07:41 PM
Thanks.
Tags
Grid
Asked by
Syed
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
ManniAT
Top achievements
Rank 2
Syed
Top achievements
Rank 1
Share this question
or