如何使用包含点列名称使用eval()()? [英] How to use Eval() with a column name that contains a dot(.)?
问题描述
在我的SQL Server表中有一栏 slno。
(是的,它包含一个点)的工作在SQL Server的罚款。然而,<%#的eval(slno)%GT;
是给了一个错误:
数据绑定:'System.Data.DataRowView'不包含名为'slno'属性。
。
块引用>这又如何解决呢?我不能更改数据库中列名:我从
获取数据存储过程
,所以我不能修改它
<&ItemTemplate中GT; <%#的eval(slno)%GT; < / ItemTemplate中>
解决方案使用
<%#((DataRowView的)的Container.DataItem)[。slno]%GT;
或者使用
<%#DataBinder.Eval的(的Container.DataItem,slno。)%>
有关MSDN参考看到<一个href=\"http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx\">http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx
编辑 - 另一种选择:
&LT;%#DataBinder.GetPropertyValue(的Container.DataItem,slno。)%&GT;
编辑2 - 按评论:
据我所知
评估
处理字符串作为其评估使用一些规则的前pression - 这些规则有点特殊处理...
GetPropertyValue
OTOH不适用这些规则(这意味着它是不是评估的完全替代
据我所知),从而不得不处理案件的能力,其中评估
的点处理导致的问题(如在这种情况下)。In my SQL Server table there is a column
slno.
(yes, it contains a dot) that is working fine in SQL Server. However,<%#Eval("slno.")%>
is giving an error:DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'slno'.
How can this be solved? I can't change column name in database: I am getting data from
stored procedure
so I cannot modify it.<ItemTemplate> <%#Eval("slno.") %> </ItemTemplate>
解决方案use
<%# ((DataRowView)Container.DataItem)["slno."] %>
Alternatively use
<%# DataBinder.Eval (Container.DataItem, "slno.") %>
For MSDN reference see http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx
EDIT - Another option:
<%# DataBinder.GetPropertyValue(Container.DataItem, "slno.") %>
EDIT 2 - as per comments:
AFAIK
Eval
handles the string as an expression which it evaluates using some rules - these rules have special handling for the dot...
GetPropertyValue
OTOH does not apply those rules (which means it is NOT a full replacement forEval
AFAIK) thus having the ability to handle cases where the dot handling ofEval
leads to problems (like in this case).这篇关于如何使用包含点列名称使用eval()()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!