Function to bind Generic Dictionary with dropdown list.

With the tip from the post How to bind Generic Dictionary with dropdown list  I've created the static method:

          //'http://blogs.msdn.com/piyush/archive/2006/10/17/how-to-bind-generic-dictionary-with-dropdown-list.aspx

        public static void ControlBinding(ListControl ctrl, Dictionary<string, string> dict)

        {

            ctrl.DataSource = dict;

            ctrl.DataValueField = "Key";

            ctrl.DataTextField= "Value";

        }

//Overload for StringDictionary      
 public static void ControlBinding(ListControl ctrl, StringDictionary dict)
        {
            ctrl.DataSource = dict;
            ctrl.DataValueField = "Key";
            ctrl.DataTextField = "Value";
        }
 

 Hopefully, it would help someone.

 Similar method for table:

       public static void ControlBinding(ListControl ctrl, DataTable tbl,string valueField, string textField)
        {
            ctrl.DataSource = tbl;
            ctrl.DataValueField = valueField;
            ctrl.DataTextField = textField;
        }
 

posted @ Tuesday, December 19, 2006 2:21 PM

Print

Comments on this entry:

# re: Function to bind Generic Dictionary with dropdown list.

Left by Ralph Krausse at 2/28/2007 7:22 AM
Gravatar
YES! This helped me...

# re: Function to bind Generic Dictionary with dropdown list.

Left by Rajesh at 10/1/2007 1:50 AM
Gravatar
Really it helped me..
Thankkkkkkkks a lot
carry on good stuff

Your comment:



 (will not be displayed)


 
 
 
Please add 5 and 8 and type the answer here:
 

Live Comment Preview:

 
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910