views:

204

answers:

1

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.

A: 

I would use JQuery to apply the CSS class after the ASP.Net engine has rendered the page and sent it down to the client. You would have to ensure that the columns have ID attributes that JQuery can find, but other than that, it should be a piece of cake.

<script type="text/javascript">
    $(document).ready(function () {
        $("#someId").addClass("className");
    }); 
</script>
camainc