DataBinding: ‘System.Data.DataRowView’ does not contain a property with the name due to “.” / Period in ColumnName

Recently I met up with error “DataBinding: ‘System.Data.DataRowView’ does not contain a property with the name”,  on page with dynamically generated Gridview on it.Error was coming at the runtime at timing of binding  the data.

I first checked for the columns in the dataset before binding to Gridview , all the columns are properly generated. then I started looking for the code which is generating gridview on fly. I was using following event to bind the data dynamically

protected void ValueDataBinding(object sender, EventArgs e)
{
object bound_value_obj = null;
Control ctrl = (Control)sender;
IDataItemContainer data_item_container = (IDataItemContainer)ctrl.NamingContainer;

bound_value_obj = DataBinder.Eval(data_item_container.DataItem, ColumnName); ( Exception was thown from above line while binding to column)

}

after much of debugging I found that ColumnName is  “Others…” and error was coming due to “.” / Period in ColumnName , the reason behind is  DataBinder.Eval Method Uses reflection to parse and evaluate a data-binding expression against an object at run time , so “.” can be treated with different , I havnt tried but I am sure it will throw the exception for other special chars also i.e. ;  , : ” ‘  etc.

This was solved by using

bound_value_obj =  DataBinder.GetPropertyValue(data_item_container.DataItem, ColumnName).ToString();


5 thoughts on “DataBinding: ‘System.Data.DataRowView’ does not contain a property with the name due to “.” / Period in ColumnName”

  1. Great post this helped me solve a very similar problem. I was getting the same error because I also had invalid characters in my field name, for me it was curly and square brackets: ) and (

    Using DataBinder.GetPropertyValue insead of DataBinder.Eval works great, thanks

  2. hey great idea thanks man. i am heavily suffered bcos of this problem very much. carry on u r good work.

  3. This is cool.Couldn’t find this solution anywhere else.Using “[” and “]” inside column names was not solving this issue of Binding.Your code solution worked like gem.Thanks!!

Leave a comment