How do I disable buttons in a gridview using C#?

I have a gridview which has a command button on it.  I would like to disable the command button if certain criteria is met.  For example if the datakey for that row is "A" then disable button else button is enabled for subsequent action.  Can this even be done?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it would be good if you handle the same using client side scripting eg. javascript
for c# to handle these things you would be making a server call, and if you can avoid that, it is good.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this can be done, in the ItemDataBound event.
the following article shows how to change the backcolor for certain rows:

what you have to do instead, is that you have to use e.Item.FindControl("your link button") and disable it when the corresponding value is A
Pratima PharandeCommented:
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
        <Columns >
            <asp:CommandField ShowEditButton="True"  />

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow)
            if (GridView1.DataKeys[e.Row.RowIndex].Value == "A")
                CommandField objComField =
                objComField.Visible = false;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

<asp:Button runat="server" ID="btn1" Text="Create" Enabled='<%# DataBinder.Eval(Container, "DataItem.FL_STATUS").ToString()=="A" %>' />

Open in new window

mbartAuthor Commented:
This is exactly what I am looking for, thank you so much for the quick response.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.