[英]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 我们可以轻松地分配
<asp:BoundField DataField="id " />
并在文件后面的代码中调用数据源。这没关系,但是如果我们的List是这样的
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>();
您将实体包装在
List<Entity> l=new List<Entity>();
but now what will we write in <asp:BoundField DataField="?" />
但是现在我们将在
<asp:BoundField DataField="?" />
写什么<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 :) <asp:BoundField DataField="?" />
我尝试使用Entity.Payload.Kloutid kloutid,但是没有成功。任何可以帮助我的人,谢谢:)
Create the following readonly property on Entity
在
Entity
上创建以下只读属性
public string PayloadKloutId
{
get { return payload.kloutId; }
}
You'll be able to bind it like this 您将能够像这样绑定它
<asp:BoundField DataField="PayloadKloutId" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.