Reputation: 39
I'm having some trouble with the DataBinder.Eval(Object, String)
method.
https://msdn.microsoft.com/en-us/library/4hx47hfe(v=vs.110).aspx
Generally the method works but not in case, when the string value contains a .
Example:
string DataField = "Trans. Due";
var value = DataBinder.Eval(container.DataItem, DataField);
I receive the following error;
{"DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Trans'."}
Have tried putting the string between square brackets and escaping the period. Have also tried casting it to a string thusly to no avail;
var value = DataBinder.Eval(container.DataItem, DataField.toString());
So I figure something in the method is confusing the string for a property? How can I make sure it uses the value simply as a string?
Upvotes: 0
Views: 39
Reputation: 14624
You can do this by using DataRowView
. Get the DataRowView
from current row then access value
of the property
by name
which you want from DataRowView
.
DataRowView rowView = (DataRowView)e.Row.DataItem;
String transDue = rowView["Trans. Due"].ToString();
Upvotes: 1