How to wirite if condition for GetValue

Aleksandar Nikolić asked on September 6, 2018 15:23

Hello, please, can you help me, how I can write an IF condition for GetStringValue()?

I cannot use Eval or something other here, just this.

I should write: If this URL exist, show the arrow

<%# GetStringValue("Url", string.Empty) %>

Recent Answers

Dragoljub Ilic answered on September 6, 2018 16:17

Hi Aleksandar,

I'm not sure in which context you are using it, but based on this code (which works): <%# IfEmpty(Eval("ArticleSummary"), "<h3>It's empty</h3>",Eval("ArticleSummary")) %>

you can try something like:

<%# IfEmpty(GetStringValue("Url", string.Empty) , "", "<span class=\"arrow\"></span>" + GetStringValue("Url")) %>

NOTE: I improvised second part for showing arrow, but you can put any html you want.

If the HTML is more complicated then simple one row change, you can add placeholder around it and try something like this:

<asp:PlaceHolder ID="ShowArrowIfLinkExist" runat="server" Visible=<%# IfEmpty(GetStringValue("Url", string.Empty) , false, true) %>>
          <p> This is some example with <i class="arrow">arrow</i> in text.</p>

Hope this will help you.

Best regards, Dragoljub

0 votesVote for this answer Mark as a Correct answer

Aleksandar Nikolić answered on September 7, 2018 07:58 (last edited on September 7, 2018 08:00)


Thank you for the replay, but unfortunately nothing works. :(

I use it in the Web parts -> Layouts, because that layout I use for one widget. Because in the form I have a filed for Url, I just can get that URL by

<%# GetStringValue("Url", string.Empty) %>

When I can use:

<%# IfEmpty(Eval("ArticleSummary"), "<h3>It's empty</h3>",Eval("ArticleSummary")) %>

this IF condition works, but here I cannot get the value by Eval.

Unfortunately, when is not Eval, other IF conditions does not work, always I have an error: Error loading the WebPart

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.