Our UX team doesn't like the checkbox for handling a boolean - they want a asp:DropDownList with two options for true/false.
My bool has to be bound using <%# Bind("") %>, as it's in the edit template of a asp:GridView.
Here is my code:
<asp:GridView ...>
...
<Columns>
...
<asp:TemplateField ...>
...
<EditItemTemplate>
<asp:DropDownList ID="ExcludedDropDown" runat="server" SelectedValue='<%# Bind("IsExcluded") %>'>
<asp:ListItem Value="false" Text="Include" meta:resourcekey="ListItemResource0"></asp:ListItem>
<asp:ListItem Value="true" Text="Exclude" meta:resourcekey="ListItemResource1"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
...
</Columns>
</asp:GridView>
With a breakpoint inside the EditItemTemplate, I tried following in the immediate window:
Eval("Exclude")
false
Where "false" would be the result of the Eval. Just for good measure, I did try to change the value of my "true" item to: "True", "T", "t", "Y", "y", "-1","0", "1", "" And all yield the same exception:
'DropDownList' has a selectedvalue which is invalid because it does not exist in the list of items.
I tried to work around using the "OnDataBinding" event, but this didn't help me at all (maybe I just did it wrong).
I prefer not to add a property to our Class that converts the bool into a string/integer (as that would work right away).
Is it impossible to bind a bool to DropDownList - and if it is, why would it make sense to have this restriction in ASP.NET? Have a hard time seeing the difference between supporting integers and boolean in DropDownList.