0
어떻게 GridView를 다음과 같은 클래스에 데이터 바인딩 할 수 있습니까?DataBind GridView에 대한 일반적인 "동적"클래스
public class GenericEntity
{
private readonly Dictionary<string, object> properties = new Dictionary<string, object>();
public object this[string propertyName]
{
get
{
if (properties.ContainsKey(propertyName))
return properties[propertyName];
else
return null;
}
set
{
if (value == null)
properties.Remove(propertyName);
else
properties[propertyName] = value;
}
}
}
이 클래스는 속성의 수를 가질 수 있으며, 컴파일시에 그 중 하나를 알 수있는 방법은 속성이 BD에서 결과 집합의 열을 직접지도하기 때문입니다 만 런타임에 존재하지 않는다.
이 GenericEntity 클래스 목록을 GridView에 어떻게 데이터 바인딩 할 수 있습니까? 나는 다음하지만 제외 얻을 시도 '이름의 속성을 포함하지 않는 클래스를 ...'
var newColumn = new BoundField();
newColumn.HeaderText = resultsetDescription.FieldDisplayName;
newColumn.DataField = resultsetDescription.FieldName;
myGridView.Columns.Add(newColumn);
myGridView.DataSource = GetListOfGenericEntities(args);
myGridView.DataBind();
편집 : 난 아직도이 SO answer 만에 언급 된 접근 방식을 구현 한
속성 예외 ... 당신이 필요로하는 모든이 나는 DataTable
이 변환 것 GridView
이 일반적인 목록을 결합하고 GridView
에 DataTable
을 결합하는 경우