如何用包含点(。)的列名使用Eval()? [英] How to use Eval() with a column name that contains a dot(.)?
问题描述
slno。
(是的,它包含一个点)在SQL Server中正常工作。但是,<%#Eval(slno。)%>
发生错误:
DataBinding:'System.Data.DataRowView'不包含名称为'slno'的属性。
怎么可以解决?我不能更改数据库中的列名称:我从存储过程
获取数据,所以我不能修改它。
< ItemTemplate> <%#Eval(slno)%> < / ItemTemplate>
使用
<%#((DataRowView)Container.DataItem)[slno。]%>
或者使用
code><%#DataBinder.Eval(Container.DataItem,slno。)%>
对于MSDN参考,请参阅 http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx
<编辑 - 另一个选项:
<%#DataBinder.GetPropertyValue(Container.DataItem, slno。)%>
编辑2 - 根据评论:
AFAIK Eval
将字符串作为使用某些规则评估的表达式处理 - 这些规则对点进行特殊处理...
GetPropertyValue
OTOH不适用这些规则(这意味着它不是 Eval
AFAIK)因此有能力处理 Eval
的点处理导致问题(例如在这种情况下)的情况。
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 for Eval
AFAIK) thus having the ability to handle cases where the dot handling of Eval
leads to problems (like in this case).
这篇关于如何用包含点(。)的列名使用Eval()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!