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();