Is there a similar way to AlternateItemTemplate to do this

自古美人都是妖i 提交于 2019-12-10 16:03:25

问题


I know that with a repeater I can use AlternatingItemTemplate and SeparatorTemplate to adopt a variety of alternating items or for the latter a consistent style / attribute between items.

But in my latest task, I require a SeperatorTemplate but only after every 3 items!

I know I can do this in the ItemDataBound and have a cheeky runningItemCount++ then use runningItemCount % 3 == 0 to place this in.

I also know I can do this using a repeater within a repeater. Just mentioning it is dirty....

I want to keep things clean to be honest, and if it's built in then it's something I want to get in the habit of using, so if anyone knows of how to do so in a nice way (no workarounds please), then please intrigue me.


回答1:


You are doing this correct, but you can use Container.ItemIndex instead of runningItemCount to keep track of the item index.




回答2:


Consider to use the ListView control. It support a GroupTemplate and GroupSeparatorTemplate templates.




回答3:


From looking in to this issue in various areas the conclusion in a nut shell is 'No there isn't'.

I had to use the method I mentioned as unfortunately there is no specific built in feature for this functionality.



来源:https://stackoverflow.com/questions/7611767/is-there-a-similar-way-to-alternateitemtemplate-to-do-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!