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

hide command buttons/links issue

1 Answer 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
El
Top achievements
Rank 1
El asked on 19 Mar 2010, 11:28 AM
I managed it to hides Add New Record button but only the one at the top. The other one at the bottom remains visible :(
if (e.Item is GridCommandItem) 
                    { 
                        GridCommandItem cmdItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0]; 
                        ((LinkButton)cmdItem.FindControl("InitInsertButton")).Visible = false
                    } 

Also how do i hide the delete button? I tried the next but it didn't work properly.

if (e.Item is GridDataItem) 
                    { 
                        GridDataItem item = (GridDataItem)e.Item; 
                        LinkButton editButton = (LinkButton)item.FindControl("EditButton"); 
                        editButton.Visible = false
                        //LinkButton deleteButton = (LinkButton)item.FindControl("DeleteButton"); 
                        //deleteButton.Visible = false; 
                    } 

the Edit button gets hidden but the delete throws an exception "Object reference not set to an instance of an object".


1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 19 Mar 2010, 01:49 PM

Hello,

You can use the following code snippet in PreRender event in order to hide the "Add New Record" button in both CommandItems.

cs:

 
    protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        GridCommandItem commandItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];  
        ((LinkButton)commandItem.FindControl("InitInsertButton")).Visible = false;  
        GridCommandItem commandItem1 = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[1];  
        ((LinkButton)commandItem1.FindControl("InitInsertButton")).Visible = false;  
    } 

I guess you are using autogenerated Delete button, if so you can use the following code to hide that.

cs:

 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            LinkButton editButton = (LinkButton)item.FindControl("EditButton");  
            editButton.Visible = false;  
            LinkButton deleteButton = (LinkButton)item.FindControl("AutoGeneratedDeleteButton");   
            deleteButton.Visible = false;   
        }   
    } 

Regards,

Shinu.

Tags
Grid
Asked by
El
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or