OnItemDataBound 的用途
您实际上会在 Repeater 上使用 OnItemDataBound 来做什么?
What would you realistically use OnItemDataBound for on a Repeater ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您实际上会在 Repeater 上使用 OnItemDataBound 来做什么?
What would you realistically use OnItemDataBound for on a Repeater ?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
“此事件为您提供了在客户端显示数据项之前访问数据项的最后机会。引发此事件后,数据项将被清空并且不再可用。”
~http://msdn.microsoft。 com/en-us/library/system.web.ui.webcontrols.datagrid.onitemdatabound.aspx
"This event provides you with the last opportunity to access the data item before it is displayed on the client. After this event is raised, the data item is nulled out and no longer available."
~http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.onitemdatabound.aspx
一种用途可以是基于仅在绑定中继器时从绑定数据项中可用的信息来动态控制生成。
One use could be dynamic control generation based on information that is only available from the bound data item at the time it is bound the Repeater.
当我需要对中继器中每个项目的数据进行一些处理时,我就使用了它。
I've used it when I needed to massage the data a bit for each item in the repeater.
如果您想要使用不属于您最初绑定到中继器的结果集的动态控件或数据来自定义模板中的单个项目,则这是必要的。
It's necessary if you want to customize an individual item within the template with dynamic controls or data that wasn't a part of the resultset you originally bound to the repeater.
这样想吧。 创建项目时,将针对该特定项目触发所有 OnDataBinding 事件。 可能有很多东西可以构建一个项目,因此可以调用许多 OnDataBinding 事件。 全部完成后,将触发该事件,以便您可以应用一些最终的“触摸”,并且所有 OnDataBinding 事件此时均已完成。
例如。 您的项目会填充 10 个数据字段,并在绑定时执行各种操作。 一旦所有数据都填满,您想要检查现在已创建的数据的某些部分,并为整个项目设置一些内容,例如整个行颜色或基于整个项目的数据的一些图标。
Think of it like this. As your item is being created, all the OnDataBinding events are firing for that specific item. There could be many things that build up one item so many OnDataBinding events could be called. Once it is all done, this is the event that is triggered so you can apply some final 'touches' and all the OnDataBinding events are done at this time.
Eg. You item fills 10 fields of data and does all sorts of stuff when bound. Once all that data is filled up you want to check certain pieces of that data that has now been created and set something to the whole item like the entire row color or some icons based on data from the whole item.
我用它来实现嵌套转发器。 在外部转发器的 ItemDataBound 事件处理程序中,您运行代码以对内部转发器的当前项实例进行数据绑定。
I've used it to implement a nested repeater. In the outer repeater's ItemDataBound event handler, you run the code to databind the current item's instance of the inner repeater.
我发现数据绑定语法难以阅读和调试。 我认为我曾经使用 OnItemDataBound 做过任何通过将数据绑定表达式放入标记中无法完成的事情,但如果我想稍后更改它,我个人发现设置要容易得多OnItemDataBound 中的一个断点,然后使用立即窗口来确定我想要渲染的内容。 我还是一个明显正在衰落的(例如 Ruby)格言的拥护者,即代码和标记应该分开。
I find data-binding syntax difficult to read and debug. I don't think I've ever done anything with OnItemDataBound that I couldn't have done by putting a data-binding expression into the markup, but if I want to change it later, I personally find it a lot easier to just set a break point in OnItemDataBound and then use the immediate window to nail down what I want to have rendered. I'm also an adherent to the apparently fading (e.g. Ruby) dictum that code and markup should be separate.