views:

470

answers:

4

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 ?

+6  A: 

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.

John Nolan
thx alot :D that was pretty helpful !
Madi D.
+3  A: 

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) %>
balexandre
+1 for the useful info :)
Madi D.
+2  A: 

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)) %>
Nick Berardi
+1 for the useful info :)
Madi D.
+1  A: 

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

Sean
+1,Thanks alot ! .. reading the article now..
Madi D.