Connecting Tech Pros Worldwide Forums | Help | Site Map

Which databind syntax to use

Kees de Winter
Guest
 
Posts: n/a
#1: Feb 19 '07
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?

--
Thanks for any help,
Kees de Winter



Eliyahu Goldin
Guest
 
Posts: n/a
#2: Feb 19 '07

re: Which databind syntax to use


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" <nospam@nospam.orgwrote in message
news:45d97117$0$11825$ba620dc5@text.nova.planet.nl ...
Quote:
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?
>
--
Thanks for any help,
Kees de Winter
>
>

Kees de Winter
Guest
 
Posts: n/a
#3: Feb 19 '07

re: Which databind syntax to use


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" <REMOVEALLCAPITALSeEgGoldDinN@mMvVpPsS.orgwrote in
message news:%232dahxAVHHA.4380@TK2MSFTNGP03.phx.gbl...
Quote:
Addresses(0).Street is not a name of a field, it is an expression. Can
your
Quote:
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" <nospam@nospam.orgwrote in message
news:45d97117$0$11825$ba620dc5@text.nova.planet.nl ...
Quote:
Hello,

I am binding an ObjectDataSource control to a custom object. A
Detailsview
Quote:
Quote:
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?

--
Thanks for any help,
Kees de Winter
>
>

Eliyahu Goldin
Guest
 
Posts: n/a
#4: Feb 19 '07

re: Which databind syntax to use


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" <nospam@nospam.orgwrote in message
news:45d98a00$0$2026$ba620dc5@text.nova.planet.nl. ..
Quote:
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" <REMOVEALLCAPITALSeEgGoldDinN@mMvVpPsS.orgwrote in
message news:%232dahxAVHHA.4380@TK2MSFTNGP03.phx.gbl...
Quote:
>Addresses(0).Street is not a name of a field, it is an expression. Can
your
Quote:
>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" <nospam@nospam.orgwrote in message
>news:45d97117$0$11825$ba620dc5@text.nova.planet.n l...
Quote:
Hello,
>
I am binding an ObjectDataSource control to a custom object. A
Detailsview
Quote:
Quote:
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?
>
--
Thanks for any help,
Kees de Winter
>
>
>>
>>
>
>

Kees de Winter
Guest
 
Posts: n/a
#5: Feb 20 '07

re: Which databind syntax to use


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" <REMOVEALLCAPITALSeEgGoldDinN@mMvVpPsS.orgwrote in
message news:Oa4VdADVHHA.3500@TK2MSFTNGP05.phx.gbl...
Quote:
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" <nospam@nospam.orgwrote in message
news:45d98a00$0$2026$ba620dc5@text.nova.planet.nl. ..
Quote:
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" <REMOVEALLCAPITALSeEgGoldDinN@mMvVpPsS.orgwrote in
message news:%232dahxAVHHA.4380@TK2MSFTNGP03.phx.gbl...
Quote:
Addresses(0).Street is not a name of a field, it is an expression. Can
your
Quote:
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" <nospam@nospam.orgwrote in message
news:45d97117$0$11825$ba620dc5@text.nova.planet.nl ...
Hello,

I am binding an ObjectDataSource control to a custom object. A
Detailsview
Quote:
shows the data from the object. "Normal" properties are shown
allright,
Quote:
Quote:
Quote:
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
Quote:
Quote:
Quote:
(just an example):
<asp:BoundField DataField="Addresses(0).Street" HeaderText=""
SortExpression="" />

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

--
Thanks for any help,
Kees de Winter


>
>
>
>

Closed Thread