How to databind a gridview to an ExpandoObject
Asked Answered
V

1

9

When I try to databind an ASP.NET GridView to an IEnumerable<ExpandoObject> using an ObjectDataSource, I get the following exception.

System.Web.HttpException (0x80004005): DataBinding: 'System.Dynamic.ExpandoObject' does not contain a property with the name 'StoreID'.

Anyone know how I could databind to ExpandoObjects?

Voracious answered 19/1, 2011 at 21:27 Comment(1)
I know it can be done - I've done it - unfortunately I lost some files from that exercise, though. If it is important I could probably reconstruct it, but the key here will be something like ICustomTypeDescriptor and/or ITypedListGathering
F
6

The opensource framework Impromptu-Interface can do this. It has a method for exposing dynamic object properties for reflection by passing in a dictionary of property names->types.

IEnumerable<dynamic> tProxiedObject = listOfExpandos.Select(x=>Impromptu.ActLikeProperties(x, x.ToDictionary(k=>k.Key,v=>typeof(object))));
Fleece answered 28/2, 2011 at 17:35 Comment(2)
This works. But it does not support two way binding. When i try to update, the object sent to the update method is empty.Meristic
@OrPaz: you could try ImpromptuInterface.MVVM nuget.org/packages/ImpromptuInterface.MVVM/4.0.13Intelligible

© 2022 - 2024 — McMap. All rights reserved.