Home All Groups Group Topic Archive Search About

How to hide the "Edit" link in DetailsView via code?

Author
22 Sep 2006 5:10 PM
turboJeeper
I need to hide the "Edit" link of a DetailsView control based on a
condition. Basically trying to set the "ShowEditButton" property to
"false" when loading the page with the DetailsView on it if the user
is not an admin. Is it possible to do via code? The commandfield links
are not templated, they're generated.

I guess if I use template fields I can control visibility then but can
it be done by setting the "ShowEditButton" property of the
CommandField in code somehow?

Author
24 Sep 2006 2:08 PM
Gaurav Vaish (www.EduJiniOnline.com)
>I need to hide the "Edit" link of a DetailsView control based on a
> condition. Basically trying to set the "ShowEditButton" property to
> "false" when loading the page with the DetailsView on it if the user
> is not an admin. Is it possible to do via code? The commandfield links

In Page_Load, before data binding happens, you may set the ShowEditButton
property appropriately:

void Page_Load(...)
{
    if(IsUserAdmin())
    {
        detailsView1.ShowEditButton = true;
    } else
    {
        detailsView1.ShowEditButton = false;
    }
}


Author
26 Sep 2006 1:37 PM
turboJeeper
Sorry but there isn't an accessible "ShowEditButton" property of the
DetailView1 control that I can see. It doesn't even show in the
IntellySense. The ShowEditButton property is actually the property of
the CommmandField object in the DetailsView control's Field collection
as far as I can tell. This is in ASP.Net 2.0 of course.

So how can I access this property?

Thanks!

On Sun, 24 Sep 2006 19:38:08 +0530, "Gaurav Vaish
\(www.EduJiniOnline.com\)" <gaurav.vaish.nospam@nospam.gmail.com>
wrote:

Show quoteHide quote
>>I need to hide the "Edit" link of a DetailsView control based on a
>> condition. Basically trying to set the "ShowEditButton" property to
>> "false" when loading the page with the DetailsView on it if the user
>> is not an admin. Is it possible to do via code? The commandfield links
>
>In Page_Load, before data binding happens, you may set the ShowEditButton
>property appropriately:
>
>void Page_Load(...)
>{
>    if(IsUserAdmin())
>    {
>        detailsView1.ShowEditButton = true;
>    } else
>    {
>        detailsView1.ShowEditButton = false;
>    }
>}
Author
26 Sep 2006 6:01 PM
Gaurav Vaish (www.EduJiniOnline.com)
> Sorry but there isn't an accessible "ShowEditButton" property of the
> DetailView1 control that I can see. It doesn't even show in the
> IntellySense. The ShowEditButton property is actually the property of
> the CommmandField object in the DetailsView control's Field collection
> as far as I can tell. This is in ASP.Net 2.0 of course.

Oops! My fault... I was actually referring to the column. Duh!
The property to be worked with for DetailView is DefaultMode -- set it to
DetailsViewMode.ReadOnly or DetailsViewMode.Edit.



Author
26 Sep 2006 6:03 PM
Gaurav Vaish (www.EduJiniOnline.com)
The property to or not auto-generate-edit-button is
AutoGenerateEditButton and not ShowEditButton.


Ignore my previous posting.

Show quoteHide quote
"turboJeeper" <turboJee***@aol.com> wrote in message
news:22bih29auv23icfov5deaor51rfpm9jpov@4ax.com...
> Sorry but there isn't an accessible "ShowEditButton" property of the
> DetailView1 control that I can see. It doesn't even show in the
> IntellySense. The ShowEditButton property is actually the property of
> the CommmandField object in the DetailsView control's Field collection
> as far as I can tell. This is in ASP.Net 2.0 of course.
>
> So how can I access this property?
>
> Thanks!
>
> On Sun, 24 Sep 2006 19:38:08 +0530, "Gaurav Vaish
> \(www.EduJiniOnline.com\)" <gaurav.vaish.nospam@nospam.gmail.com>
> wrote:
>
>>>I need to hide the "Edit" link of a DetailsView control based on a
>>> condition. Basically trying to set the "ShowEditButton" property to
>>> "false" when loading the page with the DetailsView on it if the user
>>> is not an admin. Is it possible to do via code? The commandfield links
>>
>>In Page_Load, before data binding happens, you may set the ShowEditButton
>>property appropriately:
>>
>>void Page_Load(...)
>>{
>>    if(IsUserAdmin())
>>    {
>>        detailsView1.ShowEditButton = true;
>>    } else
>>    {
>>        detailsView1.ShowEditButton = false;
>>    }
>>}