Binding asp: DropDownList SelectedValue for boolean not working - workarounds?

Our UX team does not like the flag for processing booleans - they need asp: DropDownList with two parameters for true / false.

My bool should be linked using <% # Bind ("")%>, as shown in the asp: GridView editing template.

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 EditItemTemplate, I tried the following in the nearest window:

Eval("Exclude")
false

Where "false" will be the result of Eval. For a good assessment, I tried to change the value of my "true" element to "Truth", "T", "T", "U", "U", "-1", "0", 1 "," "And all of them give the same exception:

"DropDownList" , , .

OnDataBinding, (, ).

, bool / ( ).

bool DropDownList - , ASP.NET? DropDownList.

+4
2

ListItem (True | False), . , .

enter image description here

<asp:DropDownList ID="ExcludedDropDown" runat="server" 
    SelectedValue='<%# Bind("IsExcluded") %>'>
    <asp:ListItem Value="True" Text="Include"></asp:ListItem>
    <asp:ListItem Value="False" Text="Exclude"></asp:ListItem>
</asp:DropDownList>

public class Something
{
    public string Some { get; set; }
    public bool IsExcluded { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        var collections = new List<Something>
        {
            new Something {Some = "One", IsExcluded = true},
            new Something {Some = "Two", IsExcluded = false},
        };
        GridView1.DataSource = collections;
        GridView1.DataBind();
    }
}
+5

! "" , . - ( ) . meta: resourcekey True/False . :

<asp:GridView ...>
    ...
    <Columns>
        ...
        <asp:TemplateField ...>
            ...
            <EditItemTemplate>
                <asp:DropDownList ID="ExcludedDropDown" runat="server" SelectedValue='<%# Bind("IsExcluded") %>'>
                    <asp:ListItem Value="False" Text="Include" ></asp:ListItem>
                    <asp:ListItem Value="True" Text="Exclude" ></asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
        </asp:TemplateField>
        ...
    </Columns>
</asp:GridView>
+1

All Articles