#Eval if statement in repeater

后端 未结 6 1019
野性不改
野性不改 2020-12-03 10:10

I\'m trying to check a string value inside a repeater, and if it has value then write a link, but can\'t seem to get it to work. If there is a value in myUrl then I want to

6条回答
  •  无人及你
    2020-12-03 10:58

    I would use the String.Format and include the HTML as part of the string. Admittedly, it's not the neatest piece of code ever written, but in my opinion it's the best option:

    For example the below will output an anchor tag if the property Url exists, otherwise it will output a span.

    <%# string.Format(Eval("Url") != null ? "{1}" : "{1}", Eval("Url"), Eval("Text")) %>">
    

提交回复
热议问题