How to change the background of datalist item using VB.NET code?

Go To StackoverFlow.com

0

I want to change the color of the background of an item in datalist upon some condition while binding the data? How?

2012-04-04 08:04
by Bader


2

Add a ItemDataBound event handler to the datalist

ASPX:

<asp:DataList ID="DataList1" runat="server" 
        onitemdatabound="DataList1_ItemDataBound">
</asp:DataList>

Code Behind:

Protected Sub DataList1_ItemDataBound(sender As Object, e As DataListItemEventArgs)             
    If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
         ' check condition and change styles
    End If
End Sub
2012-04-04 08:12
by mshsayem
Ads