473,396 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What is the diffreence between <%= %> and <%# %>

ad
I find there are some tag like <%= %> and <%# > in my .aspx file.

What is the diffreence between <%= %> and <%# %>
Nov 19 '05 #1
5 1871
<%="bla" %> is equal to Response.Write("bla");
<%# %> means that you are binding against an object (e.g. this is
databinding syntax).

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 19 '05 #2
ad
Thank for your immediate answer.

I have still a question:

In some text book for ASP.NET, they use

<%# Container.DataItem("FieldName") %>

to present the filed data, but In ohters, they uese

<%# DataBinder.Eval(Container, "DataItem.FieldName") %>

What is the difference between them?


"Wilco Bauwer" <wi****@gmail.com>
???????:11**********************@g14g2000cwa.googl egroups.com...
<%="bla" %> is equal to Response.Write("bla");
<%# %> means that you are binding against an object (e.g. this is
databinding syntax).

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 19 '05 #3
When you are data binding you need to fetch the value of the object you're
databinding to. Typically this is a row from a database, and for simplicity
I'll keep that as my example. So you then need a column value form the row.
This is the typical syntax for that:

<%# DataBinder.Eval(Container.DataItem, "SomeColumn")%>

The DataBinder.Eval syntax is used to dynamically fetch a value from an object
(the row, in this case), and the value is specified by the string parameter.
The value in this case is the column name. This mechanism is used for flexibility,
since you could be using a DataReader, a DataSet, DataTable, DataView, or
any other custom object to bind to. It uses reflection to fetch the value.

Container is the control that was created for this row in the databinding
control. DataGridItem, GridViewRow, RepeaterItem, whatever. Container.DataItem
is the row you're databinding to. The control holds the rows that was used
to do the data binding.

You can use other syntaxes to do data binding, but they tend to be more tightly
couple type-wise with the data source you're binding to, and thus the syntax
sometimes requires casting and it makes it uglier (if you can believe it)
than the DataBinder.Eval syntax above.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Thank for your immediate answer.

I have still a question:

In some text book for ASP.NET, they use

<%# Container.DataItem("FieldName") %>

to present the filed data, but In ohters, they uese

<%# DataBinder.Eval(Container, "DataItem.FieldName") %>

What is the difference between them?

"Wilco Bauwer" <wi****@gmail.com>
???????:11**********************@g14g2000cwa.googl egroups.com...
<%="bla" %> is equal to Response.Write("bla");
<%# %> means that you are binding against an object (e.g. this is
databinding syntax).
----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl


Nov 19 '05 #4
If you use
<%# Container.DataItem("FieldName") %>
the field's content will, simply, be displayed.

If you use
<%# DataBinder.Eval(Container, "DataItem.FieldName") %>
the field's content will be evaluated and will be returned,
depending on the field's content.

For example, if you use :
<img src='\images\<%#
Databinder.Eval(Container.DataItem,"FieldName")%>. jpg'>
with a boolean ( true/false ) field, if the boolean field returns 1,
the 1.jpg (true) image is displayed and if the boolean field returns 0,
the 0.jpg (false) image is shown.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Thank for your immediate answer.

I have still a question:

In some text book for ASP.NET, they use

<%# Container.DataItem("FieldName") %>

to present the filed data, but In ohters, they uese

<%# DataBinder.Eval(Container, "DataItem.FieldName") %>

What is the difference between them?


"Wilco Bauwer" <wi****@gmail.com>
???????:11**********************@g14g2000cwa.googl egroups.com...
<%="bla" %> is equal to Response.Write("bla");
<%# %> means that you are binding against an object (e.g. this is
databinding syntax).

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl


Nov 19 '05 #5
In addition to the other good advice you've received, I have an
article with some example code that shows what is happening underneath
the covers:

http://odetocode.com/Articles/278.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 27 Mar 2005 08:38:58 +0800, "ad" <ad@wfes.tcc.edu.tw> wrote:
Thank for your immediate answer.

I have still a question:

In some text book for ASP.NET, they use

<%# Container.DataItem("FieldName") %>

to present the filed data, but In ohters, they uese

<%# DataBinder.Eval(Container, "DataItem.FieldName") %>

What is the difference between them?


"Wilco Bauwer" <wi****@gmail.com>
???????:11**********************@g14g2000cwa.goog legroups.com...
<%="bla" %> is equal to Response.Write("bla");
<%# %> means that you are binding against an object (e.g. this is
databinding syntax).

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl


Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Francesco Moi | last post by:
Hello. I'm trying to build a RSS feed for my website. It starts: ----------------//--------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE rss PUBLIC "-//Netscape...
1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
4
by: matatu | last post by:
Hi to all, I have a xml file, a substring like: &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; which after an xslt trasform is rendered as (using xsl:output method html): &lt;a...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
2
by: Francesco Moi | last post by:
Hello. I designed a form to edit some DataBase's fields. But some of these fields contain '&lt;' and '&gt;' characters. And these characters are '<' and '>' in HTML. So if want to edit these...
34
by: Mark Moore | last post by:
It looks like there's a pretty serious CSS bug in IE6 (v6.0.2800.1106). The HTML below is validated STRICT HTML 4.01 and renders as I would expect in Opera, FrontPage, and Netscape. For some...
6
by: tentstitcher | last post by:
Hi all: I have a source xml document with an element of type string. This element contains something like the following: <stringData> &lt;Header&gt; &lt;Body&gt; </stringData> I would like to apply an...
3
by: John Nagle | last post by:
I have XML replies in a DOM which contain entity escapes, like "&amp;". What's the proper way to replace them with the ordinary characters? Preferably something that will work in most browsers? I...
4
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.