I’m looking for a way to selectively apply a CSS class to individual rows in a GridView based upon a property of the data bound item.
e.g.:
GridView’s data source is a generic list of SummaryItems and SummaryItem has a property ShouldHighlight. When ShouldHighlight == true the CSS for the associated row should be set to highlighted
any ideas?
very easy
the code above works if you use a DataTable as DataSource
change to:
just for the example above when using generics:
if you are working with Generics (List, Dictionary, etc)
keep in mind:
always return the entire object that you are populating the row with, so it is easy from here to manipulate the appearance of the data in the webpage.
you should use RowDataBound event that will trigger after the data is attached to the row object but not yet written the HTML code in the page, in this way you can check the ShouldHighlight value (I converted to a String cause I do not know the type, you can change it if you know it’s a boolean value).
this code runs much faster than megakemp code cause you’re not creating a List object and populated with the entire data source for each row…
P.S. take a look at this website, you can find several tutorials for your project using the GridView object