I have a GridView
displaying person records. I want to conditionally show a CommandField
or ButtonField
based on some property of the underlying record. The idea is to only allow a command to be performed on specific people.
What is the best way to do this? I'd prefer a declarative solution to a procedural one.
Best Answer
First, convert your
ButtonField
orCommandField
to aTemplateField
, then bind theVisible
property of the button to a method that implements the business logic:Then, in the code behind, add in the method:
The advantage here is you can test the
IsOverAgeLimit
method fairly easily.