hide insert button on radgrid

10 posts, 1 answers
  1. eric
    eric avatar
    35 posts
    Member since:
    Mar 2009

    Posted 27 May 2009 Link to this post

    How do you programatically remove or hide the insert new record button on a radgrid?  I can't directly reference the control btnAddReconItem.




    telerik:RadGrid ID="rgReconciliation" runat="server" Skin="Vista" AllowPaging="true"












    <HeaderContextMenu Skin="Vista">






    <CollapseAnimation Type="OutQuint" Duration="200" />












    <PagerStyle Mode="NextPrevAndNumeric" NextPageText="&amp;gt;" PrevPageText="&amp;lt;" />






    <MasterTableView CommandItemDisplay="Top">
























    <td width="30%">






    <asp:LinkButton ID="btnAddReconItem" runat="server" Font-Bold="true" CausesValidation="false"






    CommandName="InitInsert">Add Reconciliation Item</asp:LinkButton>












    <td width="40%">












    <td width="30%">


















































  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 27 May 2009 Link to this post

    Hi Eric,

    You can hide the "Add New Record" button in CommandItem as shown below.

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        if (e.Item is GridCommandItem) 
            Button addButton = e.Item.FindControl("AddNewRecordButton"as Button; 
            addButton.Visible = false
            LinkButton lnkButton = (LinkButton)e.Item.FindControl("InitInsertButton"); 
            lnkButton.Visible = false

  3. Daniel
    Daniel avatar
    4949 posts

    Posted 28 May 2009 Link to this post

    Hello Eric,

    The previous suggestion is valid for autogenerated buttons.

    You can access the controls in the CommandItemTemplate this way:
    private void Page_PreRender(object source, EventArgs e) 
            LinkButton lb = new LinkButton(); 
            foreach(GridItem item in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)) 
                lb =  item.FindControl("btnAddReconItem"as LinkButton; 

    Best regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. eric
    eric avatar
    35 posts
    Member since:
    Mar 2009

    Posted 06 Jul 2009 Link to this post

    The last reply works as the solution unless there are no items in the grid.  How can you hide the button then?

    This method also hides my edit and delete columns which i do not want to do.  ANy thoughts?
  5. Answer
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Jul 2009 Link to this post

    Hello Eric,

    I suppose you are trying to hide the Add Reconciliation Item link button when there are items in the grid and display it when there are no items. If thats the case, you can make a slight change to the above given code:
     protected void Page_PreRender(object source, EventArgs e) 
            LinkButton lb = new LinkButton(); 
            if (RadGrid1.MasterTableView.Items.Count != 0
                foreach (GridItem item in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)) 
                    lb = item.FindControl("btnAddReconItem"as LinkButton; 
                lb.Visible = false

  6. Javier Tia
    Javier Tia avatar
    1 posts
    Member since:
    Dec 2009

    Posted 17 Dec 2009 Link to this post

    If you want hide Add New Record use:

    <CommandItemSettings AddNewRecordImageUrl="<..IMAGE w/ TRANSPARENCY..>" AddNewRecordText="" /> 
  7. Hatim
    Hatim avatar
    3 posts
    Member since:
    Jun 2012

    Posted 05 Jul 2012 Link to this post

        <CommandItemSettings  ShowAddNewRecordButton="false"  />
  8. Jon
    Jon avatar
    36 posts
    Member since:
    Sep 2013

    Posted 11 Feb 2014 Link to this post

    Thanks Hatim for your updated posting!

    In case anyone wants to know how to do this programmatically:
    RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
  9. Chris
    Chris avatar
    6 posts
    Member since:
    Jan 2015

    Posted 20 Nov 2015 Link to this post

    And to expand Jon's note, if you're looking to do the same thing for child-grids:

    If rg.MasterTableView.Items.Count > 0 Then
        rg.MasterTableView.Items(0).ChildItem.NestedTableViews(0).CommandItemSettings.ShowAddNewRecordButton = false
    End If

  10. Eyup
    Eyup avatar
    3296 posts

    Posted 25 Nov 2015 Link to this post

    Hi Guys,

    Thank you for sharing your approaches with our community. Generally, you can also achieve this requirement using the following approach:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        if (e.Item is GridCommandItem && e.Item.OwnerTableView.Name == "OrderDetails")
            GridCommandItem item = (GridCommandItem)e.Item;
            item.Visible = false;

    Alternatively, you can also traverse the table views:

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top