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

how to get the linkbutton id in commanditemtemplate

2 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ambica
Top achievements
Rank 1
ambica asked on 19 Aug 2008, 10:55 AM
hi,

im using telerik grid, when i want to add a record it displays cancel link in commanditemtemplate column.

i don't want to display that cancel link when adding a record.

how can i get the id of that linkbutton id to visible false.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Aug 2008, 11:53 AM
Hello Ambica,

You can check out the following code to hide the CancelButton while inserting an item as shown below:
cs:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item; 
            LinkButton lnkbtn = (LinkButton)item.FindControl("CancelButton"); 
            lnkbtn.Visible = false
        } 
    } 

Thanks
Princy.
0
Daniel
Telerik team
answered on 20 Aug 2008, 02:53 PM
Hello Ambica,

The code provided by Princy applies when your edit form buttons are of type LinkButton (default). If you used ImageButton (like shown below) you should change the type in her code.

<MasterTableView CommandItemDisplay="TopAndBottom" EditMode="PopUp"
    <EditFormSettings> 
        <EditColumn ButtonType="ImageButton" CancelImageUrl="Cancel.gif"
        </EditColumn> 
    </EditFormSettings> 
</MasterTableView> 

This would be the code for PushButton:
if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) 
    GridEditFormInsertItem editItem = e.Item as GridEditFormInsertItem; 
    Button pushButton = editItem.FindControl("CancelButton"as Button; 
    if (pushButton != null) pushButton.Visible = false
}  

I believe the better approach is to use safe cast and put a simple check to be sure that you get the right control.




Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
ambica
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or