Which databind syntax to use

K

Kees de Winter

Hello,

I am binding an ObjectDataSource control to a custom object. A Detailsview
shows the data from the object. "Normal" properties are shown allright, but
I cannot get array properties to be shown. For example:

This works fine:
(In DetailsView)
<asp:BoundField DataField="drivingDirections" HeaderText="drivingDirections"
SortExpression="drivingDirections" />

But this doesn't:
Suppose there was an array property "Addresses" holding address objects
(just an example):
<asp:BoundField DataField="Addresses(0).Street" HeaderText=""
SortExpression="" />

I hope it is just a syntactical issue? Which syntax to use?
 
K

Kees de Winter

Thanks for your help Eliyahu.

Maybe it would be possible to "flatten out" an object like that but it would
not be very useable. Just imagine 10 addresses x 5 fields = 50 more
properties? And if a new address is needed the class definition needs an
update!?

Is there another solution possible? Otherwise the ObjectDataSource could
only be used with "flat" custom classes? Maybe switch from arrays to
generics?

--
Thanks again,
Kees de Winter




Eliyahu Goldin said:
Addresses(0).Street is not a name of a field, it is an expression. Can your
object expose it as a separate property? Then you could bind to it.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Kees de Winter said:
Hello,

I am binding an ObjectDataSource control to a custom object. A Detailsview
shows the data from the object. "Normal" properties are shown allright,
but
I cannot get array properties to be shown. For example:

This works fine:
(In DetailsView)
<asp:BoundField DataField="drivingDirections"
HeaderText="drivingDirections"
SortExpression="drivingDirections" />

But this doesn't:
Suppose there was an array property "Addresses" holding address objects
(just an example):
<asp:BoundField DataField="Addresses(0).Street" HeaderText=""
SortExpression="" />

I hope it is just a syntactical issue? Which syntax to use?
 
E

Eliyahu Goldin

You don't have to use asp:BoundField. You can use templatefields with
regular databinding expressions or any other ways of databinding.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Kees de Winter said:
Thanks for your help Eliyahu.

Maybe it would be possible to "flatten out" an object like that but it
would
not be very useable. Just imagine 10 addresses x 5 fields = 50 more
properties? And if a new address is needed the class definition needs an
update!?

Is there another solution possible? Otherwise the ObjectDataSource could
only be used with "flat" custom classes? Maybe switch from arrays to
generics?

--
Thanks again,
Kees de Winter




Eliyahu Goldin said:
Addresses(0).Street is not a name of a field, it is an expression. Can your
object expose it as a separate property? Then you could bind to it.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Kees de Winter said:
Hello,

I am binding an ObjectDataSource control to a custom object. A Detailsview
shows the data from the object. "Normal" properties are shown allright,
but
I cannot get array properties to be shown. For example:

This works fine:
(In DetailsView)
<asp:BoundField DataField="drivingDirections"
HeaderText="drivingDirections"
SortExpression="drivingDirections" />

But this doesn't:
Suppose there was an array property "Addresses" holding address objects
(just an example):
<asp:BoundField DataField="Addresses(0).Street" HeaderText=""
SortExpression="" />

I hope it is just a syntactical issue? Which syntax to use?
 
K

Kees de Winter

That did it, thanks!

--
Kees

[in Detailsview]
<asp:TemplateField HeaderText="HeaderText" >
<ItemTemplate>

<asp:Label Text='<%# Eval("Addresses(0).street") %>'
runat="server"></asp:Label>

</ItemTemplate>

</asp:TemplateField>



Eliyahu Goldin said:
You don't have to use asp:BoundField. You can use templatefields with
regular databinding expressions or any other ways of databinding.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Kees de Winter said:
Thanks for your help Eliyahu.

Maybe it would be possible to "flatten out" an object like that but it
would
not be very useable. Just imagine 10 addresses x 5 fields = 50 more
properties? And if a new address is needed the class definition needs an
update!?

Is there another solution possible? Otherwise the ObjectDataSource could
only be used with "flat" custom classes? Maybe switch from arrays to
generics?

--
Thanks again,
Kees de Winter




Eliyahu Goldin said:
Addresses(0).Street is not a name of a field, it is an expression. Can your
object expose it as a separate property? Then you could bind to it.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Hello,

I am binding an ObjectDataSource control to a custom object. A Detailsview
shows the data from the object. "Normal" properties are shown allright,
but
I cannot get array properties to be shown. For example:

This works fine:
(In DetailsView)
<asp:BoundField DataField="drivingDirections"
HeaderText="drivingDirections"
SortExpression="drivingDirections" />

But this doesn't:
Suppose there was an array property "Addresses" holding address objects
(just an example):
<asp:BoundField DataField="Addresses(0).Street" HeaderText=""
SortExpression="" />

I hope it is just a syntactical issue? Which syntax to use?
 

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

Top