[RESOLVED]label style

hi,

I have a label button inside a repeater.it already have a class for alignment.

I want to add the color for the label text dynamically in code behind, but is not applying.

 Dim mrklink As Label = TryCast(newitems.FindControl("lbl_ID"), Label)
                mrklink = New Label
                If val 1< val 2 Then
                    mrklink.ForeColor = Color.Red
end if


Why re you re-instantiating the label? Use the following code in the repeater ItemDateBound event

If e.Item.ItemType = ListItemType.Item or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim mrklink As Label = TryCast(newitems.FindControl("lbl_ID"), Label)
    If mrklink isNot Nothing Then                
         If val 1< val 2 Then
            mrklink.ForeColor = Color.Red
         End if
    End If
End If

Leave a Reply