OnItemDataBound 的用途

发布于 2024-07-13 15:04:21 字数 48 浏览 5 评论 0原文

您实际上会在 Repeater 上使用 OnItemDataBound 来做什么?

What would you realistically use OnItemDataBound for on a Repeater ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

心的憧憬 2024-07-20 15:04:22

“此事件为您提供了在客户端显示数据项之前访问数据项的最后机会。引发此事件后,数据项将被清空并且不再可用。”

~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

疯了 2024-07-20 15:04:22

一种用途可以是基于仅在绑定中继器时从绑定数据项中可用的信息来动态控制生成。

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.

温柔女人霸气范 2024-07-20 15:04:22

当我需要对中继器中每个项目的数据进行一些处理时,我就使用了它。

I've used it when I needed to massage the data a bit for each item in the repeater.

断舍离 2024-07-20 15:04:22

如果您想要使用不属于您最初绑定到中继器的结果集的动态控件或数据来自定义模板中的单个项目,则这是必要的。

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.

无名指的心愿 2024-07-20 15:04:22

这样想吧。 创建项目时,将针对该特定项目触发所有 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.

一梦等七年七年为一梦 2024-07-20 15:04:22

我用它来实现嵌套转发器。 在外部转发器的 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.

椵侞 2024-07-20 15:04:22

我发现数据绑定语法难以阅读和调试。 我认为我曾经使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文