views:

19

answers:

2

For example when using a gridview. When you specify the columns

BoundField for example won't work if you are binding it to a field instead of a property.

I guess this is so because when the gridview is looking for the DataField property it looks for a property and not a field. Now the question is how can i change this behavior to make it possible to use fields. I know i have to inherit from the gridview, but i don't know where to go from there.

A: 

Wrap the fields with Properties

    private string fieldA; 

    public string FieldA 
    {
      get { return fieldA; }
      set { fieldA = value; }
    }
Asad Butt
A: 

Hey,

This functionality is so wrapped into the framework and wasn't designed for extensibility so no you can't change this behavior; the only thing you can do is to create wrapper objects or wrap fields with properties.

Or render the UI in your own way, which then you lose the GridView in-built functionality.

Brian
I thought maybe I could override the DataSource property and then create a property for every field at runtime using Reflection.Emit, is this possible?
diamandiev
Might be but may I ask why? What are you binding that only has fields, and is that class customizable by you?
Brian