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

[Solved] Hiding control in CommandItemDisplay

2 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephan
Top achievements
Rank 1
Stephan asked on 06 Aug 2009, 09:19 PM
I have the following RaGrid, which displays the CommanItems "Add New Record" and "Refresh" in the Grid at TopAndBottom:
 

 

<MasterTableView Width="98%" ShowFooter="True" CommandItemDisplay="TopAndBottom">    
<CommandItemTemplate>    
    <asp:LinkButton ID="btnAddNewRecord" runat="server" CommandName="AddNewRecord" Style="vertical-align: bottom">    
        <asp:Image ID="imgAdd" runat="server" ImageUrl="~/App_ThemesCustom/images/AddRecord.gif" />   
        &nbsp;&nbsp;Add  New Record  
    </asp:LinkButton> &nbsp;&nbsp;    
    <asp:LinkButton ID="btnRefresh" runat="server" CommandName="Refresh" Style="vertical-align: bottom">    
        <asp:Image ID="imgRefresh" runat="server" ImageUrl="~/App_ThemesCustom/images/Refresh.gif" /> &nbsp;Refresh  
    </asp:LinkButton>   
</CommandItemTemplate>  

Under specific curcimstances I'd like to hide the "Add New Record" LinkButton and tried to do that on DataBound:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)   
{  
    if(e.Item is GridCommandItem)   
    {  
        if (!UserHasEditAccess())   
        {   
            this.ParentPage.FindControlRecursive(this"btnAddNewRecord").Visible = false;  
        }  
    }  

 


This code works to a degree. It hides the "Add New Record" button in the "Top" of the grid, but it is still visible on the "Bottom" of the grid.

 

 

Any idea why it's not making it invisible in both the "Top" and the "Bottom"?

 

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 07 Aug 2009, 06:48 AM
Hi Stephen,

Try with the following approach and see whether it hides the add new record button properly.

CS:
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (!UserHasEditAccess()) 
        { 
            if (e.Item is GridCommandItem) 
            { 
                GridCommandItem cmdItem = (GridCommandItem)e.Item; 
                LinkButton linkBtn = (LinkButton)cmdItem.FindControl("btnAddNewRecord"); 
                linkBtn.Visible = false
            } 
        } 
   } 


Thanks
Princy
0
Stephan
Top achievements
Rank 1
answered on 07 Aug 2009, 12:51 PM
Hi Princy,

That did it.

Thanks.
Tags
Grid
Asked by
Stephan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Stephan
Top achievements
Rank 1
Share this question
or