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.
Here's the current code:
<asp:DropDownList ID="ddlContact" runat="server"
SelectedIndex='<%# Bind("contactInfo") == null ? "" : Bind("contactInfo") %>'>
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?
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:
<asp:DropDownList ID="ddlContact" runat="server"
SelectedIndex='<%# Bind("contactInfo") ?? string.Empty %>'>