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="&gt;" PrevPageText="&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
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.
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.
This method also hides my edit and delete columns which i do not want to do. ANy thoughts?
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.
<MasterTableView> |
... |
... |
<CommandItemSettings AddNewRecordImageUrl="<..IMAGE w/ TRANSPARENCY..>" AddNewRecordText="" /> |
... |
... |
</MasterTableView> |
<
MasterTableView
>
<
CommandItemSettings
ShowAddNewRecordButton
=
"false"
/>
</
MasterTableView
>
In case anyone wants to know how to do this programmatically:
RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton =
false
;
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
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
Thanks Hatim, great answer!