How to access empty ASP.NET ListView.ListViewItem to apply a style after all databinding is done?
Posted
by Caroline S.
on Stack Overflow
See other posts from Stack Overflow
or by Caroline S.
Published on 2010-05-04T14:44:37Z
Indexed on
2010/05/04
15:58 UTC
Read the original article
Hit count: 327
We're using a ListView with a GroupTemplate to create a three-column navigation menu with six items in each column, filling in two non-data-bound rows in the last column with an EmptyItemTemplate that contains an empty HTML list item. That part works fine, but I also need to programmatically add a CSS class to the sixth (last) item in each column. That part is also working fine for the first two columns because I'm assigning the CSS class in the DataBound event, where I can iterate through the ListView.Items collection and access the sixth item in the first two columns by using a modulus operator and counter.
The problem comes in the last column, where the EmptyItemTemplate has correctly filled in two empty list items, to the last of which I also need to add this CSS class. The empty items are not included in the ListView.Items collection (that's just ListViewDataItems, and the empty items are ListViewItems). I cannot find a way to access the entire collection of ListViewItems after binding. Am I missing something?
I know I can access the empty items during ItemCreated, but I can't figure out how to determine where the item I'm creating falls in the flow, and whether it's the last one.
Any help would be appreciated, if this can even be done -- I'm a bit stuck.
© Stack Overflow or respective owner