467,074 Members | 880 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,074 developers. It's quick & easy.

Binding child objects of a custom collection

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.MyUserOpe ner,
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 ?

---------------------------------------------------------------------------------

If anyone can help out a little here that would be great!
-Demetri
Nov 19 '05 #1
  • viewed: 2887
Share:
1 Reply
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.

--
-Demetri
"Demetri" wrote:
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.MyUserOpe ner,
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 ?

---------------------------------------------------------------------------------

If anyone can help out a little here that would be great!
-Demetri

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by matty.hall@gmail.com | last post: by
3 posts views Thread by Just D | last post: by
1 post views Thread by Dot net work | last post: by
reply views Thread by Stephajn Craig | last post: by
1 post views Thread by Ruben | last post: by
3 posts views Thread by cannontrodder | last post: by
2 posts views Thread by Merk | last post: by
1 post views Thread by Suresh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.