beatsandbosons
beatsandbosons

Reputation: 39

Ensuring that the entire string is used when it contains a period

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

Answers (1)

Mairaj Ahmad
Mairaj Ahmad

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

Related Questions