I have a trashcan Icon that's red by default...but based on whether deletions are allows, I'd like to make it gray. Disabling it just makes it so it's not clickable but I need to show it gray. This is in a gridview....the <i...> tag inside the <asp:LinkButton>
has the color set to #e31c3d. On rowdatabound event, I make it enabled or disabled and if disabled, I need this style color changed to gray....not sure how to access the <i> property....
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
The bold part needs to change color to gray but it's still red...the icon is disabled for certain records depending on data so disabling works but color changing to gray does not....
Also, I don't want this on command...I"m setting the disable property and want to change control in the row databound event based on some logic
Member
95 Points
431 Posts
changing color of a trash can icon
Aug 12, 2020 09:00 PM|inkaln|LINK
I have a trashcan Icon that's red by default...but based on whether deletions are allows, I'd like to make it gray. Disabling it just makes it so it's not clickable but I need to show it gray. This is in a gridview....the <i...> tag inside the <asp:LinkButton> has the color set to #e31c3d. On rowdatabound event, I make it enabled or disabled and if disabled, I need this style color changed to gray....not sure how to access the <i> property....
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lbDelete" Font-Size="20px" CssClass="pull-left" runat="server" CommandName="delete" CommandArgument='<%# Eval("UserId","{0}") %>'>
<i class="fas fa-trash-alt" style="color:#e31c3d;"></i>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Contributor
4050 Points
1571 Posts
Re: changing color of a trash can icon
Aug 13, 2020 03:41 AM|yij sun|LINK
Hi inkaln,
Accroding to your description and codes,I suggest you could add runat and id to i tag.And then you could find the htmlcontrol to set the style.
More details,you could refer to below codes:
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting" OnRowCommand="GridView1_RowCommand"> <Columns> <asp:TemplateField HeaderText="Delete"> <ItemTemplate> <asp:LinkButton ID="lbDelete" Font-Size="20px" CssClass="pull-left" runat="server" CommandName="delete" CommandArgument='<%# Eval("Col1") %>' Text="delete"></asp:LinkButton> <i class="fa fa-trash-o" style="color:#e31c3d;" runat="server" id="trash"></i> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Code-Behind:
protected void bind() { string str, strSql; str = System.Configuration.ConfigurationManager.ConnectionStrings["aspnet-TestApplicationWithDatabase-20190820030542"].ConnectionString; SqlConnection conn = new SqlConnection(str); strSql = "select * from Test6"; SqlDataAdapter da = new SqlDataAdapter(strSql, str); DataSet ds = new DataSet(); da.Fill(ds, "Test6"); this.GridView1.DataSource = ds.Tables[0].DefaultView; this.GridView1.DataBind(); conn.Close(); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bind(); } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if(e.CommandName == "delete") { LinkButton btn = (LinkButton)e.CommandSource; btn.Enabled = false; GridViewRow row =(GridViewRow) btn.NamingContainer; HtmlControl control = (HtmlControl)row.FindControl("trash"); control.Style["color"] = "gray"; } } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { }
Result:
Best regards,
Yijing Sun
Member
95 Points
431 Posts
Re: changing color of a trash can icon
Aug 13, 2020 06:09 PM|inkaln|LINK
It's not working with the code....when I'm viewing the source, this is how it's embedded
<td>
<a id="gvPhone_ctl04_lbDelete" class="aspNetDisabled pull-left" style="font-size:20px;">
<i class="fas fa-trash-alt" style="color:#e31c3d;"></i>
</a>
</td>
The bold part needs to change color to gray but it's still red...the icon is disabled for certain records depending on data so disabling works but color changing to gray does not....
Also, I don't want this on command...I"m setting the disable property and want to change control in the row databound event based on some logic