简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM