ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Add Data to Dropdownlist,Radiobutton List etc.

Add Data to Dropdownlist,Radiobutton List etc

Source

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);

Author: Ramvilas Ramsevak Varma

Submitted on: 10 aug. 2015

Language: C#

Type: Add Data to Dropdownlist,Radiobutton List etc

Views: 4218