Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Convert to Yes/No and Empty is Null

Convert to Yes/No and Empty is Null

Scheduled Pinned Locked Moved ASP.NET
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    byka
    wrote on last edited by
    #1

    How can I handle Null and apply empty string if Null? <%# IIf(Boolean.Parse(Eval("IsReferralRequired").ToString.Trim()), "Yes", "No")%>

    J A 2 Replies Last reply
    0
    • B byka

      How can I handle Null and apply empty string if Null? <%# IIf(Boolean.Parse(Eval("IsReferralRequired").ToString.Trim()), "Yes", "No")%>

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      I think when you create a boolean, it always defaults to 0 or false Same with an integer, it defaults to 0 So if this is true, you just chack for true or 1 That's a tenary operator you wrote there in your code example. So you check for 1 value like true, and return either "Yes" or "No" depending on the value. so in c# https://msdn.microsoft.com/en-us/library/ty67wk28.aspx[^] And vb it's http://blog.dmbcllc.com/the-ternary-operator-in-vbnet/[^]

      1 Reply Last reply
      0
      • B byka

        How can I handle Null and apply empty string if Null? <%# IIf(Boolean.Parse(Eval("IsReferralRequired").ToString.Trim()), "Yes", "No")%>

        A Offline
        A Offline
        Afzaal Ahmad Zeeshan
        wrote on last edited by
        #3

        Perhaps, simply by checking the value to be null or not.

        if(variable == null) {
        variable = String.Empty; // provided variable is string type
        }

        You can also set the String.Empty as the default value (value at the declaration stage), and then inside the script-based area you can alter the values.

        The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

        B 1 Reply Last reply
        0
        • A Afzaal Ahmad Zeeshan

          Perhaps, simply by checking the value to be null or not.

          if(variable == null) {
          variable = String.Empty; // provided variable is string type
          }

          You can also set the String.Empty as the default value (value at the declaration stage), and then inside the script-based area you can alter the values.

          The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

          B Offline
          B Offline
          byka
          wrote on last edited by
          #4

          here is what I come up with however its replacing DBNull with 'No'. Instead I need to do an empty string. Please help

          <%# IIf(IsDBNull(DataBinder.Eval(Container.DataItem, "IsReferralRequired")) OrElse String.IsNullOrEmpty(DataBinder.Eval(Container.DataItem, "IsReferralRequired")) OrElse (Convert.ToBoolean(Eval("IsReferralRequired")) = False), "No", "Yes")%>

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups