Hide Edit or Delete Buttons per Row in a GridView

Discussion in 'ASP .Net' started by Kevin Frey, Nov 24, 2006.

  1. Kevin Frey

    Kevin Frey Guest

    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).
    Kevin Frey, Nov 24, 2006
    #1
    1. Advertising

  2. Kevin Frey

    Onwuka Emeka Guest

    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.




    "Kevin Frey" <> wrote in message
    news:%23y%...
    > 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).
    >
    Onwuka Emeka, Nov 24, 2006
    #2
    1. Advertising

  3. Kevin Frey

    Kevin Frey Guest

    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?)

    "Onwuka Emeka" <> wrote in message
    news:%...
    > 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.
    >
    >
    >
    >
    > "Kevin Frey" <> wrote in message
    > news:%23y%...
    >> 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).
    >>

    >
    >
    Kevin Frey, Nov 27, 2006
    #3
  4. Kevin Frey

    Kevin Frey Guest

    Never mind. These properties get set at DataBind time.

    Thanks for the help.

    "Kevin Frey" <> wrote in message
    news:%23ZDiM$...
    > 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?)
    >
    > "Onwuka Emeka" <> wrote in message
    > news:%...
    >> 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.
    >>
    >>
    >>
    >>
    >> "Kevin Frey" <> wrote in message
    >> news:%23y%...
    >>> 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).
    >>>

    >>
    >>

    >
    >
    Kevin Frey, Nov 27, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?a2Vu?=
    Replies:
    1
    Views:
    10,328
    Wiktor Zychla [C# MVP]
    Jan 23, 2006
  2. Kevin Frey
    Replies:
    0
    Views:
    428
    Kevin Frey
    Nov 19, 2006
  3. Dennis
    Replies:
    2
    Views:
    452
    Dennis
    Aug 29, 2007
  4. Ather Ali Shaikh

    Q. About Show and Hide Edit and Delete Buttons

    Ather Ali Shaikh, Oct 16, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    133
    Ather Ali Shaikh
    Oct 16, 2003
  5. 11D.Universe

    Icons for GridView Edit, Select, Update, Delete buttons?

    11D.Universe, Jun 10, 2007, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    1,014
    Jester98x
    Jun 12, 2007
Loading...

Share This Page