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.
我有一个嵌套的ListView控件,在ItemTemplate中我需要调用代码隐藏文件中的方法,以便将不同的CSS类应用于渲染表中的最后一行。
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?
容器给了我绑定的ListViewDataItem,所以我想我可以针对列表视图数据源检查这个项目,看看它是否是数据源中的最后一项,但是如何获取嵌套的数据源控制?
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.
有没有更好的方法来实现这一点,我知道可以用jquery完成,但我希望有一个C#/ ASP.net解决方案。谢谢。
2 个解决方案
#1
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";
}
#2
You could try the OnItemDataBound event of the nested one, then keep a counter running, if counter == DataSource.Count, set the td's class.
您可以尝试嵌套的OnItemDataBound事件,然后保持计数器运行,如果counter == DataSource.Count,则设置td的类。
#1
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";
}
#2
You could try the OnItemDataBound event of the nested one, then keep a counter running, if counter == DataSource.Count, set the td's class.
您可以尝试嵌套的OnItemDataBound事件,然后保持计数器运行,如果counter == DataSource.Count,则设置td的类。