Home All Groups Group Topic Archive Search About

Disable ButtonColumn button control through code

Author
6 Apr 2005 12:27 PM
Sameeksha
Hello,

Is there any way to disable a button control inside a ButtonColumn of a
datagrid ? I could get the button by using syntax like
grid.Items[rownum].cells[columnnum].controls[0] and set its enabled property
to false (((Button)grid.Items[rownum].cells[columnnum].controls[0]).Enabled =
false), but as soon as grid.DataBind() is executed after disabling, the
button is enabled again. How can it be disabled and enabled as per logic
requirements?

--
Sameeksha,
MCP (.NET)

Author
6 Apr 2005 1:30 PM
Teemu Keiski
Hi,

you would do this in ItemDataBound event for the grid (which runs for every
databound grid item when DataBind is called), when you could set it one by
one (some buttons are enabled, some aren't which you could detect from data
source). Is this what you are asking?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsider
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


Show quoteHide quote
"Sameeksha" <Sameek***@discussions.microsoft.com> wrote in message
news:34EA4AB6-1336-411D-AB21-CF50EF57A3C4@microsoft.com...
> Hello,
>
> Is there any way to disable a button control inside a ButtonColumn of a
> datagrid ? I could get the button by using syntax like
> grid.Items[rownum].cells[columnnum].controls[0] and set its enabled
> property
> to false
> (((Button)grid.Items[rownum].cells[columnnum].controls[0]).Enabled =
> false), but as soon as grid.DataBind() is executed after disabling, the
> button is enabled again. How can it be disabled and enabled as per logic
> requirements?
>
> --
> Sameeksha,
> MCP (.NET)
Author
7 Apr 2005 6:27 AM
Sameeksha
The buttoncolumn which I want to enable and disable is not databound. What I
wish to do is enable the button ONLY WHEN the datagrid row is in edit mode,
and disabled at all other times (that is after update of row is complete). So
I'm not sure if ItemDataBound event will be useful. If I have to use
ItemDataBound, how do I detect if the row is in edit mode or not?

Show quoteHide quote
"Teemu Keiski" wrote:

> Hi,
>
> you would do this in ItemDataBound event for the grid (which runs for every
> databound grid item when DataBind is called), when you could set it one by
> one (some buttons are enabled, some aren't which you could detect from data
> source). Is this what you are asking?
>
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsider
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
>
>
> "Sameeksha" <Sameek***@discussions.microsoft.com> wrote in message
> news:34EA4AB6-1336-411D-AB21-CF50EF57A3C4@microsoft.com...
> > Hello,
> >
> > Is there any way to disable a button control inside a ButtonColumn of a
> > datagrid ? I could get the button by using syntax like
> > grid.Items[rownum].cells[columnnum].controls[0] and set its enabled
> > property
> > to false
> > (((Button)grid.Items[rownum].cells[columnnum].controls[0]).Enabled =
> > false), but as soon as grid.DataBind() is executed after disabling, the
> > button is enabled again. How can it be disabled and enabled as per logic
> > requirements?
> >
> > --
> > Sameeksha,
> > MCP (.NET)
>
>
>
Author
7 Apr 2005 6:51 AM
Sameeksha
Hi,
I could achieve the enabling and disabling using ItemDataBound event as
follows:
I checked for the e.Item.ItemType property, and if it's EditItem, then I
wrote code to enable the buttons, else I'm disabling them.
Thanks for help


Show quoteHide quote
"Teemu Keiski" wrote:

> Hi,
>
> you would do this in ItemDataBound event for the grid (which runs for every
> databound grid item when DataBind is called), when you could set it one by
> one (some buttons are enabled, some aren't which you could detect from data
> source). Is this what you are asking?
>
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsider
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
>
>
> "Sameeksha" <Sameek***@discussions.microsoft.com> wrote in message
> news:34EA4AB6-1336-411D-AB21-CF50EF57A3C4@microsoft.com...
> > Hello,
> >
> > Is there any way to disable a button control inside a ButtonColumn of a
> > datagrid ? I could get the button by using syntax like
> > grid.Items[rownum].cells[columnnum].controls[0] and set its enabled
> > property
> > to false
> > (((Button)grid.Items[rownum].cells[columnnum].controls[0]).Enabled =
> > false), but as soon as grid.DataBind() is executed after disabling, the
> > button is enabled again. How can it be disabled and enabled as per logic
> > requirements?
> >
> > --
> > Sameeksha,
> > MCP (.NET)
>
>
>