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"

     

     

     

     

     

    AutoGenerateColumns="false">

     

     

     

     

     

    <HeaderContextMenu Skin="Vista">

     

     

     

     

     

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

     

     

     

     

     

    </HeaderContextMenu>

     

     

     

     

     

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

     

     

     

     

     

    <MasterTableView CommandItemDisplay="Top">

     

     

     

     

     

    <CommandItemTemplate>

     

     

     

     

     

    <table>

     

     

     

     

     

    <tr>

     

     

     

     

     

    <td width="30%">

     

     

     

     

     

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

     

     

     

     

     

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

     

     

     

     

     

    </td>

     

     

     

     

     

    <td width="40%">

     

     

     

     

     

    </td>

     

     

     

     

     

    <td width="30%">

     

     

     

     

     

    </td>

     

     

     

     

     

    </tr>

     

     

     

     

     

    </table>

     

     

     

     

     

    </CommandItemTemplate>

     

     

     

     

     

    <Columns>

     

     

     

     

     

    </Columns>

     

     

     

     

     

    </MasterTableView>

     

     

     

     

     

    </telerik:RadGrid>

     

  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.

    CS:
     
    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
        }     

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel
    Admin
    Daniel avatar
    4946 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,
    Daniel
    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.
  5. 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?
  6. Answer
    Princy
    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:
    c#:
     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
            } 
        } 

    Thanks
    Princy.
  7. 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:

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

    Posted 05 Jul 2012 Link to this post

    <MasterTableView>
        <CommandItemSettings  ShowAddNewRecordButton="false"  />
    </MasterTableView>
  9. Jon
    Jon avatar
    35 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;
  10. 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

  11. Eyup
    Admin
    Eyup avatar
    3015 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:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/hierarchical-grid-types-and-load-modes/how-to/hiding-the-expand-collapse-images-when-no-records

    Regards,
    Eyup
    Telerik
    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
UI for ASP.NET Ajax is Ready for VS 2017