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

前端 未结 4 1473
长情又很酷
长情又很酷 2020-12-11 01:02

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\'

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 01:54

    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.

提交回复
热议问题