How to code a DropDownList on a bit data type in DetailsView?

joker77

Freshman
Joined
Sep 16, 2005
Messages
38
Location
Dublin
Hi,

I'm having a bit of trouble with the DropDownList control, on a bit data type. I have one screen for inserting records, and another for updating. The insert works fine, but my update screen keeps crashing with the message "lstBluetooth has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value"

The code I have for the dropdown is:
Code:
                <asp:TemplateField HeaderText="Bluetooth">
                    <EditItemTemplate>
                        <asp:DropDownList ID="lstBluetooth" runat="server" Width="100px" 
                                          DataValueField="Bluetooth" SelectedValue='<%# Bind("Bluetooth") %>'>
                            <asp:ListItem Text="True" Value="true"/>
                            <asp:ListItem Text="False" Value="false"/>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                       <asp:Label ID="lblBluetooth" runat="server" Text='<%# Eval("Bluetooth") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
I've tried changing the Value field for the 2 ListItems to 0 and 1 (as this is all that will ever be retrieved from the field Bluetooth which is defined as a bit in the database).

The above code for the DropDownList works fine on my insert page. The template field above exists in a DetailsView control, which used a PageDataSource for binding.

Any ideas on how to get this working?
 
Back
Top