How to find control in CommandItemTemplate for RadGrid

DEVMBM picture DEVMBM · Sep 9, 2010 · Viewed 30.3k times · Source

I'm using RadGrid from Telerik with three LinkButton controls in CommandItem , and i want to hide or show them using switch statement at code behind.

<CommandItemTemplate>
   <LinkButton runat="server" ID="approveAllLink" Text="Approve All" >
   </LinkButton>
   <LinkButton runat="server" ID="approveLink" Text="Approve" >
   </LinkButton>
   <LinkButton runat="server" ID="rejectLink" Text="Reject" >
   </LinkButton>
</CommandItemTemplate>

Is there anyway solve this case?

Answer

Claudio Redi picture Claudio Redi · Sep 10, 2010

What about this?

GridItem cmdItem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0]; 
LinkButton approveAllLink = cmdItem.FindControl("approveAllLink") as LinkButton; 
LinkButton approveLink = cmdItem.FindControl("approveLink") as LinkButton; 
LinkButton rejectLink= cmdItem.FindControl("rejectLink") as LinkButton; 

// Your switch logic here