0

I want to disable / put it in read only mode or anything that will make it not functional forever. What i have is this:

 <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="btnApprove" runat="server" Text="Approve" CommandName="Approve" CommandArgument='<%# Eval("ProductID") %>' />
            </ItemTemplate>
        </asp:TemplateField>

And it looks like this: example image

Now what i want is when i click on the Approve link button, it will be then grayed out or lose its functionality. BUT ONLY FOR THAT ROW THAT I HAVE CLICKED .Any trick on how i can do that? by the way here is my code behind for it:

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                CheckBox chkRow = (row.Cells[0].FindControl("chkCtrl") as CheckBox);

                if (chkRow.Checked)
                {
                    using (SqlConnection scn = new SqlConnection("Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True"))
                    {
                        scn.Open();
                        SqlCommand cmd = new SqlCommand("update o set o.Updatedproduct = p.ProductQuantity - o.Totalproduct from CustomerProducts o inner join Products p on o.ProductID = p.ProductID WHERE o.CustomerID=@CustomerID", scn);
                        cmd.Parameters.AddWithValue("@CustomerID", SqlDbType.Int).Value = row.Cells[0].Text;
                        cmd.ExecuteNonQuery();
                        Label1.Visible = true;
                        Label2.Visible = false;
                        GridView1.DataBind();
                    }

                }
            }
        }
    }

UPDATE:

based on the image i provided, i consider also having the entire row being grayed out if possible. its as if its useless after the ink button click

faufao
  • 11
  • 1
  • 4

1 Answers1

0

You have to find your linkbutton and disable it, like this:

var lb = row.FindControl("btnApprove") as LinkButton;
//var lb = row.Cells[0].Controls[0] as LinkButton;
lb.Enabled = false;
lb.Attributes.CssStyle[HtmlTextWriterStyle.Color] = "gray";
lb.Attributes.CssStyle[HtmlTextWriterStyle.Cursor] = "default";

Actually you have to find, also the checkbox inside the row. You can also add a style to the row to make it look disabled:

 row.CssClass = "row-disabled";

<style>
    tr.row-disabled{
       color:gray;
    }
</style>
Legends
  • 21,202
  • 16
  • 97
  • 123