farnaz
farnaz

Reputation: 23

how to set a style to a linkbutton in grid as deletebutton for enable and disable effects

I have a linkbutton in grid as a deletecolumn. I disable it when a user doesn't have permission to delete records, but when the button is disabled or enabled its appearance is the same. I need to set a style to change it's appearance when it's enable state is changed. Here is my code:

 LinkButton lbDeleteCommand = e.Item.Controls[e.Item.Controls.Count - 2].Controls[0] as LinkButton;
                LinkButton lbEditCommand = e.Item.Controls[e.Item.Controls.Count - 1].Controls[0] as LinkButton;
                if (lbDeleteCommand != null)
                {
                    lbDeleteCommand.Text = "<img alt='' src='../images/Delete.gif' border='0' />";
                    lbDeleteCommand.ToolTip = "حذف اطلاعات";
                    lbDeleteCommand.Font.Name = "Tahoma";
                    lbDeleteCommand.Attributes["onclick"] = "return confirm('آیا از حذف اطلاعات انتخاب شده مطمئن هستید؟','هشدار')";
                    lbDeleteCommand.Enabled = false;


                }

please help me. thanks

Upvotes: 2

Views: 361

Answers (1)

Govind Malviya
Govind Malviya

Reputation: 13753

You can use ternary operator for that like that : create two css class for Enable and disable

<asp:LinkButton CssClass='<%# Convert.ToBoolean(Eval("IsPermission")?"EnableCssClass":"DisableCssClass")%>' >Delete<asp:LinkButton>

Upvotes: 1

Related Questions