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

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

Left by Sandeep Aparajit at 10/2/2009 12:36 PM
Gravatar
Great stuff Michael!
I would suggest you to expand this article to all possible data sources (including the derived class examples). That would become a great soruce for developers. Anyways Thanks for the info!

Sandeep Aparajit
http://sandeep-aparajit.blogspot.com

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345