I've been using the repeater control in asp.net for awhile now..and every now and then i keep forgetting to add the '#' inside the < %# DataBinder.Eval(Container.DataItem, "NAME") % >
so i was wondering what does it mean ?
I've been using the repeater control in asp.net for awhile now..and every now and then i keep forgetting to add the '#' inside the < %# DataBinder.Eval(Container.DataItem, "NAME") % >
so i was wondering what does it mean ?
It is indicating that you are binding an expression so as you demonstrated eval or bind.
Data-Binding Syntax
Data-binding expressions are contained within <%# and %> delimiters and use the Eval and Bind functions. The Eval function is used to define one-way (read-only) binding. The Bind function is used for two-way (updatable) binding. In addition to calling Eval and Bind methods to perform data binding in a data-binding expression, you can call any publicly scoped code within the <%# and %> delimiters to execute that code and return a value during page processing.
just to add...
you also have:
$
let's you Bind a Resource, like:
<%$ Resources:Menu, oktext %>
=
the most known binder sign, let's you do the same as the Response.Write method
<%= myVariable %> instead <% Response.Write(myvariable) %>
New to .NET 4.0 there is
:
which is just like the <%= %>
but HTML encodes your output. It is used like:
<%: Model.Name %>
And it is just like calling
<%= HttpServerUtility.HtmlEncode(Model.Name) %> .. or ..
<% Response.Write(HttpServerUtility.HtmlEncode(Model.Name)) %>
here is a note on the $
<%$ prefix:value %>
It creates an expression builder based on prefix and passes the value to the expression builder for evaluation. The expression builder then returns the requested value to the page
An example would be for ASP.NET 4 Routing:
<%$ RouteUrl:RouteName=ProductList %>
which evaluates the route 'ProductList' which should be in the RouteTable.Routes.
The route can be added to the RouteTable like this, in Global.asax.cs:
RouteTable.Routes.Add( "ProductList", new Route( "products", new PageRouteHandler("~/ProductList.aspx")
));
The advantage of using $ and RouteUrl, is that you can maintain all your routing and URLs in one place in Global.asax.cs.
There is some more info on $ here:
http://www.beansoftware.com/ASP.NET-Tutorials/Expression-Builder.aspx