Disable ButtonColumn button control through code

S

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

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

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?

Teemu Keiski said:
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 said:
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?
 
S

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


Teemu Keiski said:
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 said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top