Resolving datasource expression

M

M.D.M.

Hi,

I have templated databound custom control similar to repeater.

<Display:Tree id="DB" runat="server">
<Root><%# DataBinder.Eval(Container.DataItem,"Node") %><br></Root>
<Leaves><%# DataBinder.Eval(Container.DataItem,"Subnode") %>, </Leaves>
</Display:Tree>

I need display only one Node and all its subnodes then line break etc. E.g.

Node1
Subnnode11, Subnode12, ... Subnode1N
Node2
Subnnode21, Subnode22, ... Subnode2N
....

I would like to do it so : in control code I will check whether DataItem
from DataSource is from <Root> element and if yes I will display it only
once. But I do not know how to check whether DataItem is from <Root> or from
<Leaves>.

Or will you suggest me other approach ?

I want to do it so becaause HTML formatting must be on .aspx not in code
(.cs).
 
S

Steven Cheng[MSFT]

Hi Madar,

Welcome to ASPNET newsgroup.
From your description and the code snippet you provided, you're developing
a custom ASP.NET template databound control and the control will display
some certain data which has parent/children relations. You're define two
different template and you're wondering how to retrieve the template type
at runime from the binding data,yes?

Based on my understanding on custom template databound control, the
DataItem is just a propety of the "Container" , and the Container is the
custom class we defined in our web control's code. During our custom
control's creating child control period, we will loop through the
datasource(if databinding ) and instance such a "Container" class object
and use the proper template (ITemplate) to InstantiateIn it. So at this
time, it's our code logic to determine which template to use and if you
want to store this info for later use( in databinding), we can define
another Property in our Container class. For example, we define a ItemType
field so that we can later retrieving through

DataBinder.Eval(Container, "ItemType")

Not sure whether you're developing your cusom control following the guide
in the below msdn sample referenece:

#Templated Data-Bound Control Sample
http://msdn.microsoft.com/library/en-us/cpguide/html/cpcontemplateddatabound
controlsample.asp?frame=true

the public class TemplatedListItem : TableRow, INamingContainer {

in the example is just the custom "Container" class I mentioned earlier,
you can have a detailed look in it to see whether it can provide any clues.

In addition, for your databinding scenario, we can also considering other
approachs such as hierarchical databiding(nested databound controls). Here
are some related tech articles discussing on this:

#Hierarchical Data Binding in ASP.NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
/aspn-hierdatabinding.asp

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)







--------------------
| Thread-Topic: Resolving datasource expression
| thread-index: AcWMc4TfK/Lbrrq+QbOSgmsaoif4DA==
| X-WBNR-Posting-Host: 194.212.229.226
| From: =?Utf-8?B?TS5ELk0u?= <[email protected]>
| Subject: Resolving datasource expression
| Date: Tue, 19 Jul 2005 08:07:02 -0700
| Lines: 26
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:9986
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Hi,
|
| I have templated databound custom control similar to repeater.
|
| <Display:Tree id="DB" runat="server">
| <Root><%# DataBinder.Eval(Container.DataItem,"Node") %><br></Root>
| <Leaves><%# DataBinder.Eval(Container.DataItem,"Subnode") %>, </Leaves>
| </Display:Tree>
|
| I need display only one Node and all its subnodes then line break etc.
E.g.
|
| Node1
| Subnnode11, Subnode12, ... Subnode1N
| Node2
| Subnnode21, Subnode22, ... Subnode2N
| ...
|
| I would like to do it so : in control code I will check whether DataItem
| from DataSource is from <Root> element and if yes I will display it only
| once. But I do not know how to check whether DataItem is from <Root> or
from
| <Leaves>.
|
| Or will you suggest me other approach ?
|
| I want to do it so becaause HTML formatting must be on .aspx not in code
| (.cs).
|
 
S

Steven Cheng[MSFT]

Hi Madar,

Have you had a chance to look at the suggestions in my last reply or have
you got any further progress on this question. If there're any thing else
we can help, please feel free to post here.
Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| X-Tomcat-ID: 60839471
| References: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Wed, 20 Jul 2005 03:40:36 GMT
| Subject: RE: Resolving datasource expression
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| Lines: 103
| Path: TK2MSFTNGXA01.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:9997
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Hi Madar,
|
| Welcome to ASPNET newsgroup.
| From your description and the code snippet you provided, you're
developing
| a custom ASP.NET template databound control and the control will display
| some certain data which has parent/children relations. You're define two
| different template and you're wondering how to retrieve the template
type
| at runime from the binding data,yes?
|
| Based on my understanding on custom template databound control, the
| DataItem is just a propety of the "Container" , and the Container is the
| custom class we defined in our web control's code. During our custom
| control's creating child control period, we will loop through the
| datasource(if databinding ) and instance such a "Container" class object
| and use the proper template (ITemplate) to InstantiateIn it. So at this
| time, it's our code logic to determine which template to use and if you
| want to store this info for later use( in databinding), we can define
| another Property in our Container class. For example, we define a
ItemType
| field so that we can later retrieving through
|
| DataBinder.Eval(Container, "ItemType")
|
| Not sure whether you're developing your cusom control following the guide
| in the below msdn sample referenece:
|
| #Templated Data-Bound Control Sample
|
http://msdn.microsoft.com/library/en-us/cpguide/html/cpcontemplateddatabound
| controlsample.asp?frame=true
|
| the public class TemplatedListItem : TableRow, INamingContainer {
|
| in the example is just the custom "Container" class I mentioned earlier,
| you can have a detailed look in it to see whether it can provide any
clues.
|
| In addition, for your databinding scenario, we can also considering other
| approachs such as hierarchical databiding(nested databound controls).
Here
| are some related tech articles discussing on this:
|
| #Hierarchical Data Binding in ASP.NET
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
| /aspn-hierdatabinding.asp
|
| Hope also helps. Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
|
|
|
|
|
| --------------------
| | Thread-Topic: Resolving datasource expression
| | thread-index: AcWMc4TfK/Lbrrq+QbOSgmsaoif4DA==
| | X-WBNR-Posting-Host: 194.212.229.226
| | From: =?Utf-8?B?TS5ELk0u?= <[email protected]>
| | Subject: Resolving datasource expression
| | Date: Tue, 19 Jul 2005 08:07:02 -0700
| | Lines: 26
| | Message-ID: <[email protected]>
| | MIME-Version: 1.0
| | Content-Type: text/plain;
| | charset="Utf-8"
| | Content-Transfer-Encoding: 7bit
| | X-Newsreader: Microsoft CDO for Windows 2000
| | Content-Class: urn:content-classes:message
| | Importance: normal
| | Priority: normal
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| | Xref: TK2MSFTNGXA01.phx.gbl
| microsoft.public.dotnet.framework.aspnet.webcontrols:9986
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| |
| | Hi,
| |
| | I have templated databound custom control similar to repeater.
| |
| | <Display:Tree id="DB" runat="server">
| | <Root><%# DataBinder.Eval(Container.DataItem,"Node") %><br></Root>
| | <Leaves><%# DataBinder.Eval(Container.DataItem,"Subnode") %>, </Leaves>
| | </Display:Tree>
| |
| | I need display only one Node and all its subnodes then line break etc.
| E.g.
| |
| | Node1
| | Subnnode11, Subnode12, ... Subnode1N
| | Node2
| | Subnnode21, Subnode22, ... Subnode2N
| | ...
| |
| | I would like to do it so : in control code I will check whether
DataItem
| | from DataSource is from <Root> element and if yes I will display it
only
| | once. But I do not know how to check whether DataItem is from <Root> or
| from
| | <Leaves>.
| |
| | Or will you suggest me other approach ?
| |
| | I want to do it so becaause HTML formatting must be on .aspx not in
code
| | (.cs).
| |
|
|
 

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

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top