views:

117

answers:

2

I have a nested ListView control and within the ItemTemplate I need to make a call to a method in the code-behind file in order to apply a different CSS class to the final row in the rendered table.

I am calling the method as follows...

<td class="<%# GetClass(Container) %>">

Container gives me the ListViewDataItem that is being bound so I was thinking that I can check this item against the list view data source to see if it is the last item in the data source, but how do I get to the data source of the nested control?

Is there a better way of achieving this, I know it could be done with jquery but I was hoping for a C#/ASP.net solution. Thanks.

A: 

You could try the OnItemDataBound event of the nested one, then keep a counter running, if counter == DataSource.Count, set the td's class.

Colin
A: 

This is how I solved it...

protected string GetClass(ListViewDataItem container)
    {
        List<IIndividualNetworkLevel3Word> dataSource = (List<IIndividualNetworkLevel3Word>)(((ListView)container.BindingContainer).DataSource);

        if (container.DataItemIndex == dataSource.Count-1)
        {
            return string.Empty;
        }

        return "customGridItems";
    }
Si Keep