BIND LIST<DICTIONARY<STRING,STRING>> TO DROPDOWNLIST

john rob

Total Post:108

Points:756
Posted by  john rob
 1445  View(s)
Ratings:
Rate this:

var dict = new Dictionary<string,string>();

dict.Add("A","123");

dict.Add("B","456");

dict.Add("C","789");

dict.Add("D","000");

var list = new List<Dictionary<string,string>>(); //pretty much like a DataTable

list.Add(dict); //more than one dict in the list

//ddl is a dropdownlist

ddl.DataSource = list

ddl.DataTextField ="[A]";

ddl.DataValueField ="[C]";

ddl.DataBind();

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Bind List<Dictionary<string,string>> to DropDownList

    Hi John, 


    You should bind your dictionary, not list. Something like this :

    var dict = new Dictionary<string,string>();

    dict.Add("A","123");

    ddl.DataSource = dict

    ddl.DataTextField ="Key";

    ddl.DataValueField ="Value";

    ddl.DataBind();

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!