DEVMBM DEVMBM - 3 days ago 5
ASP.NET (C#) Question

How to find control in CommandItemTemplate for RadGrid

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

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
Comments