Data Binding - using inline code vs. functions vs. straight binding

J

Jordan

I'm curious if the whole point of Repeaters/Data Lists/Grids is
encapsulating additional functionality like add/update/edit/deletes, but
really does not provide any benefits when it comes to simply displaying
information.

For example, if I wanted ONLY to show information (not edit/adds/etc) in a
format that is similar, but has customized text (ex. make this word a link
if the quantity is > 0). Which of these methods would be better, if anyonc
of them can be considered "better":

1) Straight Loops w/o Using a Control
While (Dr.Read()) {
...
if (Dr.GetInt32[3] > 0) { ...}
...
}

2) Using a Repeater w/o Functions to Customize Look
<repeater >
<itemtemplate>
<table><tr><td>...</td></tr>
<%# ShowQuantityLink(Databinder.Eval(Container.DataItem,
"Quanitity")) %>
</table>
</itemtemplate>
</repeater>

3) or simply removing the function call, and putting all the function code
in the same place.

4) Also, I could use the OnItemTemplateCreated method of the Repeater object
as well...

Because all the code will be compiled before executing, does it really
matter how I choose to simply display information? (granted, selecting a
certain method provides OO benefits which I'm not getting into here)
 
M

Michael Ramey

Actually it's not always compiled beforehand. If you have any code in <% %>
tags, it doesn't get compiled until runtime by the JIT compiler. If
performance is what you are after, your first method will be the fastest. I
read an article once (which I can't find now), which compared these controls
to the "do it yourself" methods. Bottom line was, these controls are going
to take a little longer to spit the data out than if you had done it
manually. In my opinion, it's worth the wait.
 
J

Jordan

Right about the compilation. I guess I said that becuase you can't use <% %>
in a "runat=server" control, which was used in my examples, but you can use
<% %> in my manually looping....aaannnyway, you answered my question (and
I couldn't find any articles that came right out and said it, hence my
post).

Thanks, Jordan


Michael Ramey said:
Actually it's not always compiled beforehand. If you have any code in <% %>
tags, it doesn't get compiled until runtime by the JIT compiler. If
performance is what you are after, your first method will be the fastest. I
read an article once (which I can't find now), which compared these controls
to the "do it yourself" methods. Bottom line was, these controls are going
to take a little longer to spit the data out than if you had done it
manually. In my opinion, it's worth the wait.


Jordan said:
I'm curious if the whole point of Repeaters/Data Lists/Grids is
encapsulating additional functionality like add/update/edit/deletes, but
really does not provide any benefits when it comes to simply displaying
information.

For example, if I wanted ONLY to show information (not edit/adds/etc) in a
format that is similar, but has customized text (ex. make this word a link
if the quantity is > 0). Which of these methods would be better, if anyonc
of them can be considered "better":

1) Straight Loops w/o Using a Control
While (Dr.Read()) {
...
if (Dr.GetInt32[3] > 0) { ...}
...
}

2) Using a Repeater w/o Functions to Customize Look
<repeater >
<itemtemplate>
<table><tr><td>...</td></tr>
<%# ShowQuantityLink(Databinder.Eval(Container.DataItem,
"Quanitity")) %>
</table>
</itemtemplate>
</repeater>

3) or simply removing the function call, and putting all the function code
in the same place.

4) Also, I could use the OnItemTemplateCreated method of the Repeater object
as well...

Because all the code will be compiled before executing, does it really
matter how I choose to simply display information? (granted, selecting a
certain method provides OO benefits which I'm not getting into here)
 

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

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top