473,671 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1884
<%="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.DataI tem("FieldName" ) %>

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

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

What is the difference between them?


"Wilco Bauwer" <wi****@gmail.c om>
???????:11***** *************** **@g14g2000cwa. googlegroups.co m...
<%="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.Data Item, "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.DataI tem
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.DataI tem("FieldName" ) %>

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

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

What is the difference between them?

"Wilco Bauwer" <wi****@gmail.c om>
???????:11***** *************** **@g14g2000cwa. googlegroups.co m...
<%="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.DataI tem("FieldName" ) %>
the field's content will, simply, be displayed.

If you use
<%# DataBinder.Eval (Container, "DataItem.Field Name") %>
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.Data Item,"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.ed u.tw> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Thank for your immediate answer.

I have still a question:

In some text book for ASP.NET, they use

<%# Container.DataI tem("FieldName" ) %>

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

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

What is the difference between them?


"Wilco Bauwer" <wi****@gmail.c om>
???????:11***** *************** **@g14g2000cwa. googlegroups.co m...
<%="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.ed u.tw> wrote:
Thank for your immediate answer.

I have still a question:

In some text book for ASP.NET, they use

<%# Container.DataI tem("FieldName" ) %>

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

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

What is the difference between them?


"Wilco Bauwer" <wi****@gmail.c om>
???????:11**** *************** ***@g14g2000cwa .googlegroups.c om...
<%="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
2955
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 Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd"> <rss version="0.91"> ----------------//----------------------
1
6820
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
4
9640
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 href="#"&gt;text&lt;/a&gt;
2
10555
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 type="text/javascript"> <!]> </script> <script type="text/javascript"
2
22938
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 fields, the form converts them into '<' and '>'. And I want to mantain '&lt;' and '&gt;' Mi piece of code:
34
11037
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 reason, there's an annoying vertical gap between adjacent rules that doesn't go away. This looks like IE6 is incorrectly setting the margin to some arbitrary value. Does anyone know if this is a known bug at MS? If you know of one, post the...
6
24307
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 XSLT and replace all occurances of &lt; with < and &gt; with >.
3
8181
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 know about ".innerText", but that's not portable; some browsers convert escapes when reading from innerText and some don't. John Nagle
4
11924
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> </myXml> I there a way that the XSLT transformation can render the content as html rather than text?
0
8390
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8596
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4399
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1801
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.