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

4 posts, 2 answers
  1. Syed
    Syed avatar
    74 posts
    Member since:
    Mar 2009

    Posted 06 May 2009 Link to this post

    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
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 May 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 06 May 2009 Link to this post

    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
  5. Syed
    Syed avatar
    74 posts
    Member since:
    Mar 2009

    Posted 06 May 2009 Link to this post

    Thanks.
Back to Top