Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
What is the meaning of Text='<%# Eval("XXXXX") %>'.
What is the difference between
ASP.NET
<asp:Label ID="xxxxxx" runat="server" Text='<%# Eval("xxxx") %>'> 

and
ASP.NET
<asp:Label ID="xxxxxx" runat="server" Text='xxxxx'>

??
Posted
Updated 4-Jan-13 0:34am
v2

Eval is used to bind to an UI item that is setup to be read-only (eg: a label or a read-only text box), i.e., Eval is used for one way binding - for reading from a database into a UI field.

It is generally used for late-bound data (not known from start) and usually bound to the smallest part of the data-bound control that contains a whole record. The Eval method takes the name of a data field and returns a string containing the value of that field from the current record in the data source. You can supply an optional second parameter to specify a format for the returned string. The string format parameter uses the syntax defined for the Format method of the String class.
 
Share this answer
 
v2
Text='<%# Eval("xxxx") %>' - label displays dataSource's 'xxxx' field value.

Text='xxxx' - Label displays string 'xxxx'
 
Share this answer
 
The second example will have always have it's text set to xxxxx
The first example is more complicated: it gets the value of a property called xxxxx. So if the property xxxxxx is set to "Hello", the label will display Hello, using late binding. Most often this is used as part of a template (in which case the property is part of the current data), but it is possible to use it outside a template to bind to a property on the page/control's class. Eval is read only: the value is bound from the source to the control. There is a similar method Bind which is two-way, so the value of the property will be updated with the control's value. Obviously you wouldn't use Bind with a label control as the value won't change and two-way binding has a greater overhead than the one way Eval
 
Share this answer
 
hey Refer Below Link.. it will help ful for you..
http://msdn.microsoft.com/en-us/library/ms178366(v=vs.100).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900