Home All Groups Group Topic Archive Search About

How Do I Conditionally Remove An EditCommandColumn?

Author
4 May 2005 4:23 PM
DaveC
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.

Author
4 May 2005 4:28 PM
Brock Allen
In Page_Load (or somewhere similar) do this:

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

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



Show quoteHide quote
> 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.
>
Author
4 May 2005 4:36 PM
DaveC
Thanks, but the problem is that an index of 0 is the first "real"
column, not the EditCommandColumn.
Author
4 May 2005 4:47 PM
Brock Allen
> 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
Author
9 May 2005 3:01 PM
DaveC
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!