所有数据绑定完成后,如何访问空 ASP.NET ListView.ListViewItem 以应用样式?
我们使用带有 GroupTemplate 的 ListView 创建一个三列导航菜单,每列有 6 个项目,并使用包含空 HTML 列表项的 EmptyItemTemplate 填充最后一列中的两个非数据绑定行。该部分工作正常,但我还需要以编程方式将 CSS 类添加到每列中的第六个(最后一个)项目。该部分对于前两列也工作得很好,因为我在 DataBound 事件中分配 CSS 类,我可以在其中迭代 ListView.Items 集合并使用模数运算符访问前两列中的第六项和柜台。
问题出现在最后一列中,其中 EmptyItemTemplate 已正确填充两个空列表项,我还需要在最后一列中添加此 CSS 类。空项目不包含在 ListView.Items 集合中(即 ListViewDataItems,空项目是 ListViewItems)。我找不到绑定后访问整个 ListViewItems 集合的方法。我错过了什么吗?
我知道我可以在 ItemCreated 期间访问空项目,但我不知道如何确定我正在创建的项目位于流程中的位置,以及它是否是最后一个。
如果这能做到的话,任何帮助将不胜感激——我有点卡住了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ASP.Net 引擎呈现页面并将其发送到客户端后,我将使用 JQuery 应用 CSS 类。您必须确保列具有 JQuery 可以找到的 ID 属性,但除此之外,它应该是小菜一碟。
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.