DropDownList - com dictionary

<< Click to Display Table of Contents >>

Navigation:  ASP.NET > ASP Controls >

DropDownList - com dictionary

Previous pageReturn to chapter overviewNext page

aspx

 

<asp:DropDownList runat="server" ID="DropDownList1" />

 

cs

 

            Dictionary<string, string> dados = new Dictionary<string, string>();

            dados.Add("1", "Exemplo 1");

            dados.Add("2", "Exemplo 2");

            dados.Add("3", "Exemplo 3");

 

            DropDownList1.DataSource = dados;

            DropDownList1.DataTextField = "Key"; ;

            DropDownList1.DataValueField = "Value";

            DropDownList1.DataBind();