简体   繁体   中英

Assigning Value to GridView in C#

Suppose we have a list

public class MyItem
{
    public string id{ get; set; }
    public string displayName { get; set; }
}

We can easily assign <asp:BoundField DataField="id " /> and call the Datasource in the Code behind file..this is ok but if our List is like that

public class Entity

    {
        public string id { get; set; }
        public Payload payload { get; set; }
    }

public class Payload
{
    public string kloutId { get; set; }
    public string nick { get; set; }

}

you wrap up the Entity in a List<Entity> l=new List<Entity>(); but now what will we write in <asp:BoundField DataField="?" /> <asp:BoundField DataField="?" /> I tried to use kloutid, Entity.Payload.Kloutid, but that didn't worked out.Any one who can help me with this Thanks in meekness :)

Create the following readonly property on Entity

public string PayloadKloutId
{ 
    get { return payload.kloutId; }
}

You'll be able to bind it like this

<asp:BoundField DataField="PayloadKloutId" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM