Binding child objects of a custom collection

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 ?
 
G

Guest

I found the answer to the problem on this. It is VERY simple infact.

You need to override the ToString method of the child class to have it
return whatever should show in the grid. Then just specify the property as
the datafield as you would any other property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top