locked
add text-decoration-line to items in CheckBoxList RRS feed

  • Question

  • User944339287 posted

    Hi guys. I wish to add text-decoration-line to some of the items in CheckBoxList but failed.

    Can you please advise me on this.

    For Each item As ListItem In Me.CheckBoxList.Items
     
     If item.Text.Contains("YES") Then
       item.Enabled = False
       item.Attributes.Add("style", "color:#FF0046; text-decoration-line: line-through;")
     End If
    
    Next



    Monday, December 2, 2019 11:09 AM

All replies

  • User3690988 posted

    I used this:

    Me.CheckBoxList1.Items(x).Attributes.Add("style", "color:#FF0046; text-decoration: line-through;")

    Monday, December 2, 2019 2:50 PM
  • User288213138 posted

    Hi kengkit,

    For Each item As ListItem In Me.CheckBoxList.Items
     
     If item.Text.Contains("YES") Then
       item.Enabled = False
       item.Attributes.Add("style", "color:#FF0046; text-decoration-line: line-through;")
     End If
    
    Next

    I tesed your code, it works fine in my chrome brower. Are you running your application in the IE or Edge brower?

    My test code:

    <asp:CheckBoxList ID="CheckBoxList1" runat="server">
                    <asp:ListItem Text="YES"></asp:ListItem>
                    <asp:ListItem Text="NO"></asp:ListItem>
                </asp:CheckBoxList>
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        For Each item As ListItem In Me.CheckBoxList1.Items
    
            If item.Text.Contains("YES") Then
                item.Enabled = False
                item.Attributes.Add("style", "color:#FF0046; text-decoration-line: line-through;")
            End If
        Next
    End Sub

    The result:

    Note: The text-decoration-line property is not compatible with Edge and IE.

    More information about text-decoration-line property you can refer to this link:https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration-line

    Best regards,

    Sam

    Tuesday, December 3, 2019 2:02 AM