DropdownList inside of a formview binding RRS feed

  • Question

  • User977421240 posted

    I'm having difficulting getting my binding right on a DropdownList that I've built for my FormView. I've been tweaking for a few hours here and can't seem to get around it. Pretty sure I've missed the obvious.  Can someone pull me out of the weeds?  My item list is hard coded so all I need is to push the resulting selection to my SQLDatasource field "AssetType". Here is the code for the DDL and you'll note the commented out asp:Label which is when uncommented is the functional label equivalent of this which this DDL is intended to replace.

    <%-- <asp:Label Text='<%# Bind("AssetType") %>' runat="server" ID="AssetTypeLabel" /> --%>
    <asp:DropDownList runat="server" ID="AssetTypeLabel" SelectedValue='<%# Eval("AssetType") %>'>
        <asp:ListItem>"DB2 Cluster"</asp:ListItem>
        <asp:ListItem Selected="True">"Desktop"</asp:ListItem>
        <asp:ListItem>"DNS Appliance"</asp:ListItem>
        <asp:ListItem>"EXCH Resource Cluster"</asp:ListItem>
        <asp:ListItem>"HyperV Cluster"</asp:ListItem>
        <asp:ListItem>"HyperV Guest Appliance"</asp:ListItem>
        <asp:ListItem>"HyperV Guest OS"</asp:ListItem>
        <asp:ListItem>"IBM PwrX Blade Server"</asp:ListItem>
        <asp:ListItem>"IBM PwrX Server"</asp:ListItem>
        <asp:ListItem>"IDS/IPS Device"</asp:ListItem>
        <asp:ListItem>"Mainframe Tape"</asp:ListItem>
        <asp:ListItem>"Net Access Card Ctl"</asp:ListItem>
        <asp:ListItem>"Net Video Converter"</asp:ListItem>
        <asp:ListItem>"Net Video Recorder"</asp:ListItem>
        <asp:ListItem>"Network Appliance"</asp:ListItem>
        <asp:ListItem>"Network Appliance (Virtual)"</asp:ListItem>
        <asp:ListItem>"Physical Tape"</asp:ListItem>
        <asp:ListItem>"Remote Mgmt"</asp:ListItem>
        <asp:ListItem>"SAN Device"</asp:ListItem>
        <asp:ListItem>"Server Enclosure"</asp:ListItem>
        <asp:ListItem>"SQL Cluster"</asp:ListItem>
        <asp:ListItem>"VIOS Cluster(NR)"</asp:ListItem>
        <asp:ListItem>"VIOS Guest OS"</asp:ListItem>
        <asp:ListItem>"VMWare Guest OS"</asp:ListItem>
        <asp:ListItem>"VOIP Gateway"</asp:ListItem>
        <asp:ListItem>"VOIP Phone"</asp:ListItem>
        <asp:ListItem>"Windows FO Cluster"</asp:ListItem>
        <asp:ListItem>"x86 Blade Server"</asp:ListItem>
        <asp:ListItem>"x86 Standard Server"</asp:ListItem>

    Thanks for any help you can render!


    Follow up from last week.... This didn't make any sense to me so I started tearing it down and reassembling it and realized that I had positioned the DDL in the wrong  spot.  It 'still should have worked' but so as to focus on the issue with the correct set of parameters I moved it to the correct position and found that I have the same issue but it shows up a bit differently because of some code behind that I have at work. Ending result is this:

    'AssetTypeLabel' has a SelectedValue which is invalid because it does not exist in the list of items.
    Parameter name: value 

    Now one thing that I did find curious to me when building the DDL was that the keyword 'SelectedValue' did not pop up in InteleSense which I would have expected it to have done, so there may be something there.

    Again, any ideas, suggestions, or clues would be welcomed!

    Friday, August 19, 2016 7:43 PM


  • User977421240 posted

    Okay Going to update this with the solution as I could not find it anywhere but did stumble upon it through experimenting. Two slight changes made the differences for me....

    In the SelectedValue swapping out Eval for Bind and then turning on autopostbackSo now my opening for my DDL reads:
    <asp:DropDownList runat="server" ID="AssetTypeLabel" SelectedValue='<%#Bind("AssetType")%>'>

    Works like a champ!

    Thanks for looking at even though I had no responses you let me vent and helped!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 22, 2016 8:27 PM