|
|
Here's a simple way that demonstrates how to bind a Dictionary to an ASP.NET DropDownList control
<asp:DropDownList ID="ddlRelatives" runat="server">
</asp:DropDownList>
C#
Dictionary<int, string> dicRel = new Dictionary<int, string>();
dicRel.Add(1, "Father");
dicRel.Add(2, "Mother");
dicRel.Add(3, "Brother");
dicRel.Add(4, "Sister");
dicRel.Add(5, "Others");
ddlRelatives.DataSource = dicRel;
ddlRelatives.DataTextField = "Value";
ddlRelatives.DataValueField = "Key";
ddlRelatives.DataBind();
VB.NET
Dim dicRel As New Dictionary(Of Integer, String)()
dicRel.Add(1, "Father")
dicRel.Add(2, "Mother")
dicRel.Add(3, "Brother")
dicRel.Add(4, "Sister")
dicRel.Add(5, "Others")
ddlRelatives.DataSource = dicRel
ddlRelatives.DataTextField = "Value"
ddlRelatives.DataValueField = "Key"
ddlRelatives.DataBind()
'Like' us on our FaceBook page if you find this blog useful. Thanks!
Did you like this post?
|
|
|
||
|
|
|
|
Save on Delicious |
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |




comments
3 Responses to "Bind an ASP.NET DropDownList to a Dictionary"It says null exception
Thanks ! It helped me ! ;-)
This is a great start. Could you include the definition of ddlRelatives? Also, with the addition of MVC to asp.net, an example of the MVC UI code would rock too. Thanks much. Steve
Post a Comment