Groups | Blog | Home
all groups > asp.net > april 2006 >

asp.net : puzzle over <%# %> evaluation


ChrisA
4/16/2006 11:01:02 PM
I have a Repeater that contains two controls, an Anchor (Not runat=server)
and my own Custom Control (runat=server). Each has an attribute whose value
contains <%# %> expressions. The Anchor gets an evaluated value, while my
custom control gets the raw <%# %> characters.
Is there anyway to get my control's parameter evaluated??
Teemu Keiski
4/17/2006 12:00:00 AM
It can seem like that if the property of the control etc is not covered
fully by the data-binding expression.That's because essentially anchor etc
with no runat="server" it is anyway literal that is produced, so evaluating
it is no big deal. With custom control it's not dealing with literal but
assigning a value to custom control's property

For example: This won't work

ImageUrl='http://www.server.com/<%#DataBinder.Eval(Container.DataItem,"somefield")%>'

but this does work

ImageUrl='<%#DataBinder.Eval(Container.DataItem,"somefield","http://www.server.com/{0}")%>'

(of course, in v2 DataBinder.Eval is just Eval and Container.DataItem is not
needed into the expression but 100% same idea apply)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

[quoted text, click to view]

bruce barker (sqlwork.com)
4/17/2006 9:28:06 AM
for databinding to work

1) must be a server control, have runat=server, or created in codebehind
2) the parameter value must start with "<%#" and end with "%>"
3) the Databind method must be called


-- bruce (sqlwork.com)



[quoted text, click to view]

AddThis Social Bookmark Button