IList を GridView にバインドしています。IMyInterface は次のようになります
public interface IMyInterface: IHasTotalHours, IHasLines
{
DateTime GoalStartDate { get; set; }
DateTime GoalEndDate { get; set; }
}
次のようにインスタンスを Grid にバインドします。
IList<IMyInterface> instance= GetMyData();
myGrid.DataSource = instance;
myGrid.DataBind();
これをグリッドにバインドすると、グリッドに表示される唯一のメンバーは、IMyInterface の直接のメンバーである GoalStartDate と GoalEndDate です。
何故ですか?グリッドが継承する他のインターフェイスのメンバーを表示するにはどうすればよいですか?
更新 継承されたインターフェイスは、次のような単純なデータ プロパティを定義します
public interface IHasTotalHours
{
string Description { get; set; }
int Hours{ get; set; }
}
public interface IHasLines
{
double TotalLines { get; set; }
double LinesPerHour { get; set; }
}
IMyInterface を実装するクラスがあります。
public class MyClass : IMyInterface
{
public string Description { get; set; }
public int Hours { get; set; }
public double TotalLines { get; set; }
public double LinesPerHour { get; set; }
public DateTime GoalStartDate { get; set; }
public DateTime GoalEndDate { get; set; }
}
これらは IMyInterface としてキャストされ、GridView にバインドしているリストに返されます。