G
Guest
Someone posted the following back in June and I am now doing the same thing.
I'll just paste what was asked and see if anyone can give us an answer:
---------------------------------------------------------------------------------
I have a custom collection of objects, each of which includes a child
object called MyUserOpener. In declarative binding, I can bind this
property to a label in a template control with the following syntax:
<%# DataBinder.Eval(CType(Container.DataItem.MyUserOpener,
AAA_Business.AAA_User), ("AAA_User__UserName"))%>
So far so good, this works fine.
I'm now trying to generate this datagrid dynamically incode. I'm using
reflection to inspect the properties of an object and generating a
column for each property, then binding the custom collection to the
grid, so my code looks something like this:
For Each ObjProperty As PropertyInfo In ObjProperties
Dim PropName As String = ObjProperty.Name.ToString()
Dim DataColumn As New BoundColumn
DataColumn.HeaderText =
PropName.Substring(TableName.Length +
2).Replace("_", " ")
DataColumn.DataField = PropName
Me.m_grid.Columns.Add(DataColumn)
End If
Next
This works perfectly to generate bound columns for the simple
properties of my object, but I'm stumped trying to generate a column
for the complex binding to the child property. I understand how to
generate the template column but I can't figure out how to translate
the DataBinder.eval databinding statement to replicate the complex
binging in code behind.
Can anyone help ?
I'll just paste what was asked and see if anyone can give us an answer:
---------------------------------------------------------------------------------
I have a custom collection of objects, each of which includes a child
object called MyUserOpener. In declarative binding, I can bind this
property to a label in a template control with the following syntax:
<%# DataBinder.Eval(CType(Container.DataItem.MyUserOpener,
AAA_Business.AAA_User), ("AAA_User__UserName"))%>
So far so good, this works fine.
I'm now trying to generate this datagrid dynamically incode. I'm using
reflection to inspect the properties of an object and generating a
column for each property, then binding the custom collection to the
grid, so my code looks something like this:
For Each ObjProperty As PropertyInfo In ObjProperties
Dim PropName As String = ObjProperty.Name.ToString()
Dim DataColumn As New BoundColumn
DataColumn.HeaderText =
PropName.Substring(TableName.Length +
2).Replace("_", " ")
DataColumn.DataField = PropName
Me.m_grid.Columns.Add(DataColumn)
End If
Next
This works perfectly to generate bound columns for the simple
properties of my object, but I'm stumped trying to generate a column
for the complex binding to the child property. I understand how to
generate the template column but I can't figure out how to translate
the DataBinder.eval databinding statement to replicate the complex
binging in code behind.
Can anyone help ?