Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DataBinder.Eval() in style attribute of an asp.net control

I've a asp.net linkbutton inside asp.net repeater control which renders multiple link buttons. I want to set the style of each and every linkbutton dynamically.

I'm trying

style="color:#6D7B8D;font-size:<%# DataBinder.Eval(Container.DataItem, "Title")%>;"

But i'm getting "The server tag is not well formed" error.

Any ideas?

like image 634
NLV Avatar asked Aug 08 '10 14:08

NLV


2 Answers

My understanding is that using server tags for attributes requires that the server tag be used for the entire attribute value. Try changing it to this:

style='<%# "color:#6D7B8D;font-size:" + DataBinder.Eval(Container.DataItem, "Title") + ";" %>'

Notice how the entire style attribute is being constructed in C# code between the server tags.

like image 86
Kirk Woll Avatar answered Nov 01 '22 22:11

Kirk Woll


Write it like that:

style='color:#6D7B8D;font-size:<%# DataBinder.Eval(Container.DataItem, "Title")%>;'

With single quotes instead of double quotes around the style

like image 32
Amr Elgarhy Avatar answered Nov 01 '22 22:11

Amr Elgarhy