简体   繁体   中英

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

您可以这样使用三元运算符:为Enable和disable创建两个CSS类。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM