<%# Eval("状态") %> 或 <%# DataBinder.Eval(Container.DataItem, "state")%>
有何区别?
<%# Eval("State") %>
放在 aspx
页面中与放在
<%# DataBinder.Eval(Container.DataItem, "State") %>
aspx
页面中
What is the difference between having
<%# Eval("State") %>
in your aspx
page, versus having
<%# DataBinder.Eval(Container.DataItem, "State") %>
in your aspx
page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Eval("State")
是DataBinder.Eval(Container.DataItem, "State")
语法的简化形式。 它仅适用于数据绑定模板控件内部。有关详细信息,请参阅MSDN 文档。
Eval("State")
is a simplified form of theDataBinder.Eval(Container.DataItem, "State")
syntax. It only works inside of data-bound template controls.For more info, see the MSDN documentation.
没有区别。 “Eval”方法只是 DataBinder.Eval(Container.DataItem, "blah") 方法的快捷方式。
There is no difference. The "Eval" method is just a shortcut for the DataBinder.Eval(Container.DataItem, "blah") method.
尽管 文档指出使用
Eval
(TemplateControl.Eval 准确地说)实际上调用 DataBinder.Eval 并且它们的任务是执行完全相同的工作。
这是正确的,但仅使用
Eval
意味着 ASP.NET 本身会解析数据绑定的对象。 它在内部通过堆栈执行此操作,调用Control.DataBind()
时会在堆栈中添加项目。 诀窍在于,仅当控件的Page
属性此时为非null
时才会发生这种情况。如果当您需要解析
DataItem
时Page
管理的堆栈不是最新的,则Page.GetDataItem() 方法将给出异常,并显示类似消息
DataBinder.Eval
在这些情况下仍然有效,因为您手动为其提供目标对象,因此 ASP.NET 不需要自行执行任何解析。There are a lot of differences between
<%# Eval %>
and<%# DataBinder.Eval %>
under the covers, even though the documentation states that usingEval
(TemplateControl.Eval
to be exact) actually callsDataBinder.Eval
and that their task is to do exactly the same job.That is correct, but using just
Eval
means that ASP.NET itself resolves the object that is databound. It does this internally with a stack where items are added whenControl.DataBind()
is called. The trick is that this happens only if thePage
property of the control is non-null
at that point.If the
Page
-managed stack isn't up to date when you get to the point thatDataItem
needs to be resolved, thePage.GetDataItem()
method will give an exception with a message likeDataBinder.Eval
still works in those circumstances because you provide it the target object manually, so ASP.NET doesn't need to do any resolving on its own.Eval方法只是后者的一个捷径
the Eval method is just a shortcut of the latter
我看过下面的代码
所以我猜它们略有不同。
I have seen following code
So I guess they slightly different.