Link to home
Create AccountLog in
Avatar of Chiliyago
ChiliyagoFlag for United States of America

asked on

Binding DropDownList to Dictionary<string><string>

Trying to bind a DropDown to a Dictionary<string><string> gets the following error. What property should I be using if it does not like "Keys" and "Values"?

DataBinding: 'System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' does not contain a property with the name 'Keys'.


<asp:ObjectDataSource ID="StatesDataSource" runat="server"
    SelectMethod="_USStates" TypeName="Utils"></asp:ObjectDataSource>

<asp:DropDownList
     ID="_drp_State"
     runat="server"
     DataSourceID="StatesDataSource"
     DataValueField="Keys"
     DataTextField="Keys">
</asp:DropDownList>
SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Chiliyago

ASKER


Does not like Key either.


Error:
DataBinding: 'Utils+States' does not contain a property with the name 'Key'.


<asp:ObjectDataSource ID="StatesDataSource1" runat="server"
    SelectMethod="_USStates" TypeName="Utils"></asp:ObjectDataSource>


<asp:DropDownList
                                ID="_drp_State"
                                runat="server"
                                DataSourceID="StatesDataSource2"
                                DataValueField="Key"
                                DataTextField="Key"
                                SelectedValue='<%#Bind("State")%>'
                                >
                               
                            </asp:DropDownList>
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.