Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Eval() with a column name that contains a dot(.)?

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>
like image 548
jams Avatar asked Sep 27 '11 19:09

jams


1 Answers

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

like image 61
Yahia Avatar answered Oct 06 '22 01:10

Yahia