c# - How do I change a ListView dynamically on DataBound? -
i have listview template, puts bunch of data in, x y z.
i want hide show columns based on criteria, have itemdatabound event, don't know how actual listview row can things it.
any ideas?
you can access listviewitemeventargs' item property @ current item (the 1 being bound data).
the sample code below (which shows how customize listview item in itemdatabound event) taken msdn documentation:
protected void contactslistview_itemdatabound(object sender, listviewitemeventargs e) { label emailaddresslabel; if (e.item.itemtype == listviewitemtype.dataitem) { // display e-mail address in italics. emailaddresslabel = (label)e.item.findcontrol("emailaddresslabel"); emailaddresslabel.font.italic = true; system.data.datarowview rowview = e.item.dataitem system.data.datarowview; string currentemailaddress = rowview["emailaddress"].tostring(); if (currentemailaddress == "orlando0@adventure-works.com") { emailaddresslabel.font.bold = true; } } }
Comments
Post a Comment