2013-07-19 2 views
0

동적 데이터를 사용하는 데이터 격자가 있습니다. 데이터 그리드가 포함 된 페이지에 대해 page_init 이벤트에서 동적 데이터를 활성화합니다. 런타임에 동적 데이터의 유형을 설정할 수 있기를 바랍니다. 문자열로 설정할 클래스의 이름이 있습니다. 나는 이것을 어떻게하는지 알 수 없다. 내 기업이 문자열의 이름 제공 할 수 없기 때문에이 작동하지 않습니다 분명히런타임시 DataGrid 동적 데이터 사용

Dim myGrid As GridView = DirectCast(retrieveGrid.FindControl("gridResults"), GridView) 
myGrid.EnableDynamicData(GetType(*MyEntityNameAsAString*) 

:

는이 같은 동적 데이터를 설정합니다. 문자열을 엔티티 유형으로 변환하려면 어떻게해야합니까?

Type.GetType(entityname) 

그리고

Type.GetType(AssemblyName.entityname) 

를 그리고 둘 다 작동 것 같다 : 나는 시도했다. 즉, 이러한 문 중 하나를 사용하여 형식을 가져올 수 없습니다.

답변

0

OK, 이런 식으로 해결 ... I 객체 이름의 엔티티 객체를 얻는 함수 생성 :

이어서 그리드 함수의 결과에 기초하여, 동적 데이터 사용 설정
Public Function GetEntity(ByVal entityName As String) As Object 
    'Get the assembly 
    Dim assem As Assembly = Nothing 
    assem = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory & "/bin/AsbestosEntities.dll") 
    'Get all classes in the assembly 
    Dim AllEntities As Type() = assem.GetTypes() 
    Return AllEntities.FirstOrDefault(Function(e) e.FullName = entityName) 
End Function 

:

Dim EntityType As Type = GetEntity(general_retrieve.gr_entity_set_name) 
myGrid.EnableDynamicData(EntityType) 
관련 문제