Hide Edit or Delete Buttons per Row in a GridView

K

Kevin Frey

Hello. I asked this question a while back and got no response, so I thought
I'd have another shot.

When I display a list of records in a GridView, I want to be able to vary
the presence of the Edit and Delete buttons per row depending on eg. the
user's security permissions for that row, or attributes associated with the
record (eg. a purchase order that has been dispatched to a supplier cannot
be deleted).

Can anyone tell me the correct method to go about this?

The track I am currently taking is to build a specialised CommandField
object, and hiding the appropriate controls from within a data-binder. I'm
doing this so I don't have to reimplement much of CommandField
(InitializeCell specifically).

Is there any easier way to achieve this? (To be honest the whole
data-binding strategy seems very circuitous at times for cases like this).
 
O

Onwuka Emeka

Im not very sure i get your problem clearly, but wouldn't doing something
like this solve your problem?
<asp:CommandField ShowDeleteButton="True"
Visible='<%#IsDeleteVisible(Eval("AProperty"))%>'>' />

<asp:CommandField ShowEditButton="True"
Visible='<%#IsEditVisible(Eval("AProperty"))%>'/>

where IsDeleteVisible and IsEditVisible are functions that takes a value of
a property bound to your grid to determine if the button should show.
 
K

Kevin Frey

Yes, I guess that is pretty much a representation of what I am trying to
achieve.

Since I don't really use use declarative syntax for our circumstance,
however, when in the process of creating the control tree does this Eval get
evaluated?

(eg. at the time the cell is initialised or via a databinding operation?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top