How Do I Conditionally Remove An EditCommandColumn?

Discussion in 'ASP .Net Datagrid Control' started by DaveC, May 4, 2005.

  1. DaveC

    DaveC Guest

    Hi,

    I have a DataGrid control that "by default" comes up with an
    EditCommandColumn. However, I don't want all users to see this. How
    do I conditionally remove the EditCommandColumn? Thanks in advance for
    your help.
     
    DaveC, May 4, 2005
    #1
    1. Advertising

  2. DaveC

    Brock Allen Guest

    In Page_Load (or somewhere similar) do this:

    if (!User.IsInRole("TheRoleYouCareAbout"))
    {
    grid.Columns[TheColumnIndexYouCareAbout].Visible = false;
    }

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi,
    >
    > I have a DataGrid control that "by default" comes up with an
    > EditCommandColumn. However, I don't want all users to see this. How
    > do I conditionally remove the EditCommandColumn? Thanks in advance
    > for your help.
    >
     
    Brock Allen, May 4, 2005
    #2
    1. Advertising

  3. DaveC

    DaveC Guest

    Thanks, but the problem is that an index of 0 is the first "real"
    column, not the EditCommandColumn.
     
    DaveC, May 4, 2005
    #3
  4. DaveC

    Brock Allen Guest

    > Thanks, but the problem is that an index of 0 is the first "real"
    > column, not the EditCommandColumn.


    Hmm, I'd have to go look into why this is. But for a quick alternative answer,
    you can always create your own TemplateColumn, add the <asp:Button runat=server
    CommandName="Edit" ... /> and then dynamically set it Visible=false.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen
     
    Brock Allen, May 4, 2005
    #4
  5. DaveC

    DaveC Guest

    Brock,

    Thank you very much for your help. My statement about 0 being the
    index of the first "real" column was based on the fact that I was
    indexing off of a DataColumnCollection instead of the DataGrid itself!
    I believe that I'm all set now by doing just what you originally said.
    Again, thank you very much!
     
    DaveC, May 9, 2005
    #5
    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. RobS

    EditCommandColumn validation

    RobS, Dec 8, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    1,403
    Peter Blum
    Dec 11, 2003
  2. Rick
    Replies:
    1
    Views:
    476
    Richard Ryerson
    Feb 2, 2004
  3. Richard Ryerson
    Replies:
    0
    Views:
    2,632
    Richard Ryerson
    Jan 28, 2004
  4. George Durzi

    CausesValidation of editcommandcolumn

    George Durzi, Feb 12, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    974
    George Durzi
    Feb 12, 2004
  5. angus
    Replies:
    1
    Views:
    531
    angus
    May 14, 2004
Loading...

Share This Page