I have an "action" column in my repeater which shows actions a user can select for an item. The column contains ASP.NET HyperLink or LinkButton controls. Some actions are based on whether a user is in a role, which I determine programatically. I'm struggling with the best way to dynamically generate this column when I populate the repeater. Now I am assigning in-line code to the Visible property of each control, but I feel that is sloppy and not very straight forward. Would I be better served using a PlaceHolder control and populating that at runtime? What kind of methods do other people use for situations such as this?
+3
A:
The "normal" way to apply any sort of dynamic rendering to a Template based control such as the Repeater
is to handle the ItemCreated
or ItemDataBound
events.
In your particular case, you could check appropriate conditions within that event handler and toggle the visibility of the relevant "Action" column.
Also, see this question where Ian Quigley posted a code snippet that should serve as a good example for you. It may also help to read my own answer which shows how to use visibility toggling in inline code.
Cerebrus
2009-06-01 13:30:53
Good stuff... thanks!
Mike C.
2009-06-01 14:13:41
My pleasure... You're most welcome. :-)
Cerebrus
2009-06-01 16:42:42