Tuesday, September 22, 2009

Databind column which has dot [.] in the name

I banged my head for 3 hours to figure out how we can use DataBinder.Eval() if we have dot(.) in column name and at last I figured it out . So I would like to provide solution before someone bang their head.......

Basically I have a database table with column ,"ASP.NET" , and I want to bind it to label control.

if we use DataBinder.Eval(DataItem, "ASP.NET");
then you get Error saying Column "ASP" is not found!
because "Eval" ignores text after dot(.)

so to make this work use
DataBinder.GetPropertyValue(DataItem, "ASP.NET"); //we are using "GetPropertyValue" instead of "Eval".

This should fix your problem.....

No comments:

Post a Comment