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

My SQL Server table has a slno. column slno. (yes, it contains a dot), which works fine in SQL Server. However, <%#Eval("slno.")%> Gives an error:

DataBinding: "System.Data.DataRowView" does not contain a property named "slno".

How can this be solved? I can’t change the column name in the database: I get data from the stored procedure , so I can’t change it.

 <ItemTemplate> <%#Eval("slno.") %> </ItemTemplate> 
+8
source share
4 answers

using

 <%# ((DataRowView)Container.DataItem)["slno."] %> 

Alternatively use

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

For MSDN help see http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx

EDIT is another option:

 <%# DataBinder.GetPropertyValue(Container.DataItem, "slno.") %> 

EDIT 2 - according to the comments:

AFAIK Eval treats the string as an expression, which it evaluates using some rules - these rules have special processing for the point ...

GetPropertyValue OTOH does not apply these rules (this means that it is NOT a complete replacement for Eval AFAIK), thus being able to handle cases where handling Eval points leads to problems (as in this case).

+9
source

I used DataBinder.GetPropertyValue () as follows:

 DataBinder.GetPropertyValue(Container.DataItem, "Name of my Fields with(Parentheses)") 

and worked like a charm in an ASP.NET VB project.

0
source

You can use SELECT AS in your SELECT SQL statement.

 SELECT Tabl1.slno. AS slno_no_dot from Table1 

than

 <ItemTemplate> <%#Eval("slno_no_dot") %> </ItemTemplate> 
0
source

Do not use DataBinder.eval() ; eval() cannot read the field after the dot (.).

Use DataBinder.GetPropertyValue() instead

-2
source

All Articles