Chiliyago
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.Generi c.KeyValue Pair`2[[Sy stem.Strin g, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193 4e089],[Sy stem.Strin g, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193 4e089]]' does not contain a property with the name 'Keys'.
<asp:ObjectDataSource ID="StatesDataSource" runat="server"
SelectMethod="_USStates" TypeName="Utils"></asp:Obj ectDataSou rce>
<asp:DropDownList
ID="_drp_State"
runat="server"
DataSourceID="StatesDataSo urce"
DataValueField="Keys"
DataTextField="Keys">
</asp:DropDownList>
DataBinding: 'System.Collections.Generi
<asp:ObjectDataSource ID="StatesDataSource" runat="server"
SelectMethod="_USStates" TypeName="Utils"></asp:Obj
<asp:DropDownList
ID="_drp_State"
runat="server"
DataSourceID="StatesDataSo
DataValueField="Keys"
DataTextField="Keys">
</asp:DropDownList>
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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:Obj
<asp:DropDownList
ID="_drp_State"
runat="server"
DataSourceID="StatesDataSo
DataValueField="Key"
DataTextField="Key"
SelectedValue='<%#Bind("St
>
</asp:DropDownList>