how to make a user control that uses templates?

  • Thread starter Bennett Haselton
  • Start date
B

Bennett Haselton

Are there any samples of how to create a user control that uses
templates, like the <ItemTemplate> and <HeaderTemplate> of the
Repeater control?

I tried searching for user control samples on the Web but couldn't
find any that used templates.

What I'm (still) trying to do is display a hierarchical listing of
data rows from a table that have a parent-child relationship, e.g.
rows representing user posts on a message board, with some rows having
a parent_posting_ID field set to the ID of the post that the message
is replying to. Like:

learning ASP
|
+- Re: learning ASP
|
+- Re: learning ASP
.......|
.......+- Re: learning ASP

debugging ASP code
|
+- Re: debugging ASP code

(The Microsoft.Web.UI.WebControls.TreeView control seems like overkill
since it uses client-side scripting to make nodes expandable and
collapsable, which I don't need, and may not work well in other
browsers or browsers with scripting turned off.)

So I was thinking if I could create a user control with templates, I
could create one with a <NodeTemplate> that would display the data for
the node (e.g. "Re: learning ASP" in the example above), and a
<NodePrefix> template that would precede any node except a top-level
node (the plus sign in my little ASCII art above), and a
<IndentationPrefix> template that would repeat itself a certain number
of times to indent the node over the right amount, to indicate its
depth in the hierarchy.

Of course if anyone knows an easier, built-in way, that would be ideal
:)

-Bennett
 

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