或 <%# DataBinder.Eval(Container.DataItem, "state")%>">

<%# Eval("状态") %> 或 <%# DataBinder.Eval(Container.DataItem, "state")%>

发布于 2024-07-09 04:48:11 字数 295 浏览 5 评论 0原文

有何区别?

<%# 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 技术交流群。

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

发布评论

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

评论(5

遗弃M 2024-07-16 04:48:11

Eval("State")DataBinder.Eval(Container.DataItem, "State") 语法的简化形式。 它仅适用于数据绑定模板控件内部。

有关详细信息,请参阅MSDN 文档

Eval("State") is a simplified form of the DataBinder.Eval(Container.DataItem, "State") syntax. It only works inside of data-bound template controls.

For more info, see the MSDN documentation.

夜唯美灬不弃 2024-07-16 04:48:11

没有区别。 “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.

抹茶夏天i‖ 2024-07-16 04:48:11

尽管 文档指出使用 Eval (TemplateControl.Eval 准确地说)实际上调用 DataBinder.Eval 并且它们的任务是执行完全相同的工作。

这是正确的,但仅使用 Eval 意味着 ASP.NET 本身会解析数据绑定的对象。 它在内部通过堆栈执行此操作,调用 Control.DataBind() 时会在堆栈中添加项目。 诀窍在于,仅当控件的 Page 属性此时为非 null 时才会发生这种情况。

如果当您需要解析 DataItemPage 管理的堆栈不是最新的,则 Page.GetDataItem() 方法将给出异常,并显示类似消息

诸如 Eval()XPath()Bind() 之类的数据绑定方法只能在数据绑定上下文中使用控制。

DataBinder.Eval 在这些情况下仍然有效,因为您手动为其提供目标对象,因此 ASP.NET 不需要自行执行任何解析。

There are a lot of differences between <%# Eval %> and <%# DataBinder.Eval %> under the covers, even though the documentation states that using Eval (TemplateControl.Eval to be exact) actually calls DataBinder.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 when Control.DataBind() is called. The trick is that this happens only if the Page 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 that DataItem needs to be resolved, the Page.GetDataItem() method will give an exception with a message like

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

DataBinder.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.

吃不饱 2024-07-16 04:48:11

Eval方法只是后者的一个捷径

the Eval method is just a shortcut of the latter

耳钉梦 2024-07-16 04:48:11

我看过下面的代码

<%# (DataBinder.Eval(Container.DataItem, "ApplicationId").ToString() == "-1" ? "N/A" : Eval("ApplicationId").ToString()) %>

所以我猜它们略有不同。

I have seen following code

<%# (DataBinder.Eval(Container.DataItem, "ApplicationId").ToString() == "-1" ? "N/A" : Eval("ApplicationId").ToString()) %>

So I guess they slightly different.

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