Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

GridView Button Field, can I enable/disable the button in the column in code behind

I have in my code right now where I can make the column visible or not visible such as:

<asp:ButtonField Text="Publish" ShowHeader="false" HeaderStyle-BackColor="white" ButtonType="Button" CommandName="Publish">
                                    <ItemStyle HorizontalAlign="Center" Width="150px" />
                                    <HeaderStyle HorizontalAlign="Center" Width="150px" />
                                </asp:ButtonField>

this is column 6:

if my condition then:
 GridView1.Columns[6].visible = false;

I want to always show it but make the buttons enabled or disabled?
Avatar of Sammy
Sammy
Flag of Canada image

You need to do this in the RowDataBound event of the GridView
Avatar of sbornstein2
sbornstein2

ASKER

can you provide an example at sammy please to handle the enable
ASKER CERTIFIED SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks Sammy really appreciate your help
One last question Sammy.  Once the button is clicked I do the following in the row command:

if (e.CommandName=="Publish")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = GridView1.Rows[index];
            string BookFormatID = row.Cells[1].Text;

for some reason the commandargument is "" and it throws an error.  Any idea?  I am trying to get the row to get the cell text of column 1.
Input string was not in correct format.  I beleive before it would be a number the commandargument
Forget it, I figured it out Sammy, thanks again.

CommandArgument="<%# Container.DataItemIndex %>"
Sorry I was too busy today