Add Data to Dropdownlist,Radiobutton List etc.

public static void   AddItemsToDropdownRadioEtc<T>(ref T control,DataTable data)
        {
            dynamic ControlToAdd = (T)Convert.ChangeType((object)control, typeof(T));
            ControlToAdd.DataSource = data;
            ControlToAdd.DataValueField = "MajorID";
            ControlToAdd.DataTextField = "MajorName";
            ControlToAdd.DataBind();
        }
Example:
AddItemsToDropdownRadioEtc<DropDownList>(ref DropDownList1,dataTable1);

Description

Add Data to Dropdownlist,Radiobutton List etc

Details

Double click on the code to select all.

 

;