473,395 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
1 3142
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: matty.hall | last post by:
There's a lot of information out there about data-binding UI objects (i.e. derived from Control) to non-UI custom business objects. Is it possible to do the same without any UI being involved at...
3
by: Just D | last post by:
Hi, If anybody needs to show some data retrieved from the database table, what method is more preferrable? 1. DataSet ds = ...; DataGrid.Data.Source.ds; DataGrid.Bind(); 2. Write a custom...
1
by: Dot net work | last post by:
Hello. I have an interesting data binding scenario: I have a repeater control. It repeats a typical custom web user control. I also have a collection object, and each collection element...
0
by: Stephajn Craig | last post by:
I've built a customized collection class that has strongly typed objects in it. I have a collection class called LogEntryCollection with LogEntry objects in it. Each LogEntry object has certain...
1
by: Ruben | last post by:
I have a collection (PersonCollection inherits collectionbase and implements ITypedList it's a collection of Person objects) this collection also implements the IComponent interface, so I can drag...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
3
by: cannontrodder | last post by:
I am displaying names and other details of my users in a Formview control by binding my custom business object to it. My custom object also has a property that is a collection of boolean values and...
2
by: Merk | last post by:
I'm new to .NET (using 2.0) and was wondering how to go about binding a collection of custom classes to a DataGrid. The class exposes 5 read-only String properties. I would like for each of...
1
by: Suresh | last post by:
Using ASP.NET 1.1 ---------------------- I have a custom collection of object that I'm binding to a datagrid. Each of these objects have another collection inside them. I have a user control...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.