Eval inside an ASP.net repeater doesn't work inside another control

半世苍凉 提交于 2020-01-06 08:13:41

问题


I have a Reapter control with a custom server side control inside of it. When I place the code:

<%# Eval("DateAdded") %>

inside the item template of the repeater it works fine, but when I place it inside the custom server control inside the repeater, it doesn't work. Is it possible to do something like Parent.Eval() or Container.Eval() to get back to the context of the Reapeter rather than the custom control?


回答1:


The repeater is databound, the control that you are placing this eval statement in isn't. You'll need to pass the value to the control using a property.

For Example:

<uc1:MyControl MyProperty='<%# Eval("DateAdded") %>' />

You can now access the MyProperty property inside your control to access this value.




回答2:


It should work. Can you supply more context/code for the server control?

Also, are you using single quotes to set properties on a control dynamically using eval? Double quotes should throw an error, not just be ignored.

MyProperty='<%# Eval("DateAdded") %>'


来源:https://stackoverflow.com/questions/5967840/eval-inside-an-asp-net-repeater-doesnt-work-inside-another-control

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