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

hide insert button on radgrid

10 Answers 1254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
eric
Top achievements
Rank 1
eric asked on 27 May 2009, 07:12 PM

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>

 

10 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 May 2009, 04:33 AM
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.
0
Daniel
Telerik team
answered on 28 May 2009, 06:54 AM
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.
0
eric
Top achievements
Rank 1
answered on 06 Jul 2009, 06:44 PM
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?
0
Accepted
Princy
Top achievements
Rank 2
answered on 07 Jul 2009, 06:49 AM
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.
0
Javier Tia
Top achievements
Rank 1
answered on 17 Dec 2009, 09:49 PM
If you want hide Add New Record use:

<MasterTableView> 
... 
... 
<CommandItemSettings AddNewRecordImageUrl="<..IMAGE w/ TRANSPARENCY..>" AddNewRecordText="" /> 
... 
... 
</MasterTableView> 
0
Hatim
Top achievements
Rank 1
answered on 05 Jul 2012, 09:41 AM
<MasterTableView>
    <CommandItemSettings  ShowAddNewRecordButton="false"  />
</MasterTableView>
0
Gaurab
Top achievements
Rank 1
answered on 11 Feb 2014, 05:05 PM
Thanks Hatim for your updated posting!

In case anyone wants to know how to do this programmatically:
RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
0
Chris
Top achievements
Rank 1
answered on 20 Nov 2015, 06:28 PM

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

0
Eyup
Telerik team
answered on 25 Nov 2015, 12:59 PM
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
0
Chris
Top achievements
Rank 1
answered on 23 Apr 2018, 09:23 PM

Thanks Hatim, great answer!

Tags
Grid
Asked by
eric
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Daniel
Telerik team
eric
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Javier Tia
Top achievements
Rank 1
Hatim
Top achievements
Rank 1
Gaurab
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Eyup
Telerik team
Chris
Top achievements
Rank 1
Share this question
or