次のようなデータがあるとします。
class Location
{
public int Id { get; private set; }
public string City { get; set; }
public string State { get; set; }
public string Country { get; set; }
}
class Friend
{
public int Id { get; }
public string FriendName { get; set; }
public Location Address { get; set; }
public int Age { get; set; }
public bool IsReliable { get; set; }
}
次のように、ASP.NET 2.0 GridView コントロールを独自の IList にバインドするとします。
GridView1.DataSource = new List<Friend>
{
new Friend { Name = "...", Age = 22, ... }
};
GridView1.DataBind();
しかし、次のカスタム キャプション/列ヘッダーを使用して、GridView に次の列のみを配置したいと考えています。
- FriendName (列キャプション: フレンド名)
- 都市 (列キャプション: 都市)
- 年齢 (列キャプション: 年齢)
それ、どうやったら出来るの?
つまり、GridView コントロールを独自のカスタム IList のカスタム メンバーに選択的にバインドするにはどうすればよいでしょうか。