I have a nullable varchar column in a table in my database.
I am binding a gridview to this table via an objectdatasource and have a TemplateField like so:
<asp:RadioButtonList ID="rblRequirementOption" RepeatDirection="Horizontal" runat="server" RepeatLayout="Flow"
SelectedValue='<%#Bind("RequirementOption")%>'>
<asp:ListItem Value="" Text="" style="display: none" />
<asp:ListItem Value="Need" Text="Need"></asp:ListItem>
<asp:ListItem Value="Do Not Use" Text="Do Not Use"></asp:ListItem>
</asp:RadioButtonList>
If there are any null values in that column in the table, I get the error:
"'rblRequirementOption' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value"
So as you can see, I have tried to add a placeholder radio button with a value of "" to accomodate the null values, which is the commonly advised method to handle this error, but in this case, it seems that "" and DBNull.Value are not considered equivalent.
Surely I don't have to convert nulls to a zero length string before binding do I?
UPDATE
Actually, this is the correct syntax to do it. (I was futzing around with a default value substitute and got all mixed up.)