I have some code that I started to manage, and it started to crash due to some data missing from the database. This case may happen in the future, so I would like to gracefully handle zeros in the interface.
Here's the current code:
<asp:DropDownList ID="ddlContact" runat="server" SelectedIndex='<%# Bind("contactInfo") == null ? "" : Bind("contactInfo") %>'>
This does not seem to affect it, and the page still throws a NullReferenceException. It must be Bind () due to the two-way data binding requirement, so I cannot use Eval (). Any ideas?
I tried using the null collision operator "??" but this gives me a compilation error that states that Bind () does not exist in the current context. It might look like this:
<asp:DropDownList ID="ddlContact" runat="server" SelectedIndex='<%# Bind("contactInfo") ?? string.Empty %>'>
Carl
source share