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>
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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).
Method 2
I Used DataBinder.GetPropertyValue() as it follows:
DataBinder.GetPropertyValue(Container.DataItem, "Name of my Fields with(Parentheses)")
and Worked like a Charm on a ASP.NET VB Project.
Method 3
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>
Method 4
I recently ran into the same issue in a self-written customcontrol. In some cases I need to use the syntax “object.property” and sometimes I need to use “columnname.with.dots”. Finally I solved it by using a Try-Catch block:
object value;
try
{
// Try "Object.Property" approach...
value = DataBinder.Eval(container.DataItem, Fieldname);
}
catch
{
// fallback for columns containing dots or other special characters
value = DataBinder.GetPropertyValue(container.DataItem, Fieldname);
}
Method 5
Do not use DataBinder.eval(); eval() can not read field after dot(.).
Instead, use DataBinder.GetPropertyValue()
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0