title: Testing for null, inline, on an ASP.net Bind() call
body: <p>I've got a bit of code that I started to manage, and it's begun to fail due to some data missing in the database. This case could happen in the future, so I'd like to gracefully handle the nulls in the front end.</p>
  
  <p>Here's the current code:</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlContact" runat="server"
    SelectedIndex='&lt;%# Bind("contactInfo") == null  ? "" : Bind("contactInfo") %&gt;'&gt;
  </code></pre>
  
  <p>It doesn't seem to have any affect on it, and the page still throws a NullReferenceException. It needs to be a Bind() due to the two-way data binding requirement, so I can't use Eval(). Any ideas? </p>
  
  <p>I've tried to use the null-coallescing operator "??" but that gives me a compilation error stating that Bind() does not exist in the current context. That could would look like this:</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlContact" runat="server"
    SelectedIndex='&lt;%# Bind("contactInfo") ?? string.Empty %&gt;'&gt;
  </code></pre>