数据绑定表达式语法 [英] Data Binding Expression Syntax

查看:57
本文介绍了数据绑定表达式语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我刚刚将一个大型Web项目从VB.NET转换为C#,我得到了一些非常好的b $ b奇怪的运行时错误。显然,在整个ASPX页面中,该项目的VB

版本使用表达式<%#

Container.DataItem(" columnName")%>在< ItemTemplate>内标签为

DataGrid。显然虽然这在VB.NET中运行良好,但出于某种原因,C#

会对它产生影响。我发现用<%#

DataBinder.Eval(Container.DataItem," columnName")%>替换这些表达式让错误消失了

,但我不明白为什么。在我看来,嵌入在ASPX页面中的

数据绑定表达式的评估应该在两种语言中完全相同




任何人都可以解释这种语法的神秘规则吗?


I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can''t figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work identically
in both languages?

Can anyone explain the arcane rules of this syntax?

推荐答案

你应该对类型进行类型转换。在datagrid的情况下,它看起来像


<%#(DataRowView)Container.DataItem(" columnName")%>


DataBinder.Eval在运行时使用反射,因此速度慢得多。


Eliyahu


" JV" <乔********** @ goisc.com>在消息中写道

news:%2 **************** @ tk2msftngp13.phx.gbl ...
You should typecast Container. In the case of datagrid it will look like

<%# (DataRowView)Container.DataItem("columnName") %>

DataBinder.Eval uses reflection at runtime and, therefore, is much slower.

Eliyahu

"JV" <jo**********@goisc.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Container.DataItem(" columnName")%>在< ItemTemplate>内标签为
DataGrid。显然虽然这在VB.NET中运行良好,但出于某种原因,C#
会对它产生影响。我发现用<%#
DataBinder.Eval(Container.DataItem," columnName")%>替换这些表达式让错误消失了,但我不明白为什么。在我看来,嵌入在ASPX页面中的数据绑定表达式的评估应该在两种语言中都相同吗?

任何人都可以解释这种语法的神秘规则吗? br />

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can''t figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work identically
in both languages?

Can anyone explain the arcane rules of this syntax?



也许试试:

<%#Container.DataItem [" columnName"]%>


" JV" <乔********** @ goisc.com>在消息中写道

news:%2 **************** @ tk2msftngp13.phx.gbl ...
Maybe try:
<%# Container.DataItem["columnName"] %>

"JV" <jo**********@goisc.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Container.DataItem(" columnName")%>在< ItemTemplate>内标签为
DataGrid。显然虽然这在VB.NET中运行良好,但出于某种原因,C#
会对它产生影响。我发现用<%#
DataBinder.Eval(Container.DataItem," columnName")%>替换这些表达式让错误消失了,但我不明白为什么。在我看来,嵌入在ASPX页面中的数据绑定表达式的评估应该在两种语言中都相同吗?

任何人都可以解释这种语法的神秘规则吗? br />

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can''t figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work identically
in both languages?

Can anyone explain the arcane rules of this syntax?



首先尝试了另一个错误。


" Sharon" < SH **** @ void.null>写了
Tried that first, got another error.

"Sharon" <sh****@void.null> wrote
也许试试:
<%#Container.DataItem [" columnName"]%>

" JV" <乔********** @ goisc.com>写了
Maybe try:
<%# Container.DataItem["columnName"] %>

"JV" <jo**********@goisc.com> wrote

我刚刚将一个大型Web项目从VB.NET转换为C#,我得到了一些非常奇怪的运行时错误。显然,在整个ASPX页面中,该项目的VB版本使用表达式<%#
Container.DataItem(" columnName")%>在< ItemTemplate>内标签为
DataGrid。显然虽然这在VB.NET中运行良好,但出于某种原因,C#
会对它产生影响。我发现用<%#
DataBinder.Eval(Container.DataItem," columnName")%>替换这些表达式让错误消失了,但我不明白为什么。在我看来,嵌入在ASPX页面中的数据绑定表达式的评估应该在两种语言中相同地工作吗?

任何人都可以解释这些神秘的规则这个语法?

I just converted a big web project from VB.NET to C# and I got some very
strange runtime errors. Apparently, throughout the ASPX pages, the VB
version of this project used the expression <%#
Container.DataItem("columnName") %> inside an <ItemTemplate> tag for
DataGrid. Apparently though this works fine in VB.NET, for some reason C#
chokes on it. I have found that replacing those expressions with <%#
DataBinder.Eval(Container.DataItem, "columnName")%> makes the errors go
away, but I can''t figure out why. It seems to me that the evaluation of
data binding expressions embedded in the ASPX page should work
identically
in both languages?

Can anyone explain the arcane rules of this syntax?



这篇关于数据绑定表达式语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆