【问题标题】:How to change the colour of an icon at some condition如何在某些情况下更改图标的颜色
【发布时间】:2019-01-24 02:02:04
【问题描述】:

我有一个链接按钮,我在其中使用了一个很棒的图标。
我想在 C# 服务器端代码中的某些条件下更改图标的颜色。

<asp:LinkButton ID="TemplateEditLinkButton" runat="server" CommandName="TemplateEdit" CssClass="btn grid-btn-link">
    <i class='fa fa-pencil-square-o' aria-hidden='true'></i> 
    <span>Edit</span>                                                                             
</asp:LinkButton>                



 LinkButton templateEditLinkButton = e.Row.FindControl("TemplateEditLinkButton");
    if ((e.Row.Cells[10].Text == "False")) {
        //here;change color condition
    }

}                                                                                                                                       

【问题讨论】:

  • 请尝试回答

标签: c# asp.net icons


【解决方案1】:

您可以使用三元运算符检查剃须刀页面上的 html 控件内的条件。

内部代码

protected bool isColorchange { get; set; }

然后在行动

protected void Page_Load (object sender, EventArgs e)
 {
     LinkButton templateEditLinkButton = 
    e.Row.FindControl("TemplateEditLinkButton");
      if ((e.Row.Cells[10].Text == "False")) {
              this.isColorchange = true;
      }
       else{
       this.isColorchange=false; 
       }

  }

查看

<asp:LinkButton ID="TemplateEditLinkButton" runat="server" CommandName="TemplateEdit" 
CssClass="btn grid-btn-link">
<i class='<%= (isColorchange==true?"classone":"classtwo") %>' aria-hidden='true'></i> 
<span>Edit</span>                                                                             
 </asp:LinkButton>   

请阅读here

【讨论】:

  • 请先告诉我你想要改变行为的条件
  • 你能告诉我什么是 commandname 吗?您是否将其传递到剃须刀页面?
  • 我正在使用 asp.net
  • 我知道你正在使用 asp.net webform,让我知道这里的“命令名”是什么,如果没有给出这段代码的定义,我自己无法得出结论。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
  • 1970-01-01
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 2019-04-20
相关资源
最近更新 更多