. Net:
The. datasource attribute of dropdownlist, ListBox, checkboxlist, rodiobuttonlist, and other controls can be used.
Listitemcollection. Note: datavaluefield and datatextfield attribute values must be specified during binding!
If no field is specified, the values of value and text are both text.
Listitemcollection listitems = New Listitemcollection ();
Listitems. Add ( New Listitem ( " Test data 1 " , " 1 " ));
Listitems. Add ( New Listitem ( " Test data 2 " , " 2 " ));
Radiobuttonlist1.datasource = Listitems;
/* Specifies the field value. If this parameter is not specified, the default value is:
Radiobuttonlist1.datavaluefield = "text ";
Radiobuttonlist1.datatextfield = "text ";
*/
Radiobuttonlist1.datavaluefield = " Value " ; // Value of the Control Value Field
Radiobuttonlist1.datatextfield = " Text " ; // Text Field Value of the control
Radiobuttonlist1.databind ();
Data Controls: repeater, datalist, detailview, and gridview can all be directly bound to a data source of a generic type, such:
List <> to implement ilist <> interface data. Public ClassPerson
{
Private StringName;
Private IntAge;
Public String Name
{
Get { Return This . Name ;}
Set { This . Name = Value ;}
}
Public Int Age
{
Get { Return This . Age ;}
Set { This . Age = Value ;}
}
Public Person ( String Name, Int Age)
{
This . Name = Name;
This . Age = Age;
}
}
// Use the Data Control:
Ilist < Person > Testlist = New List < Person > ();
Testlist. Add ( New Person ( " Zhang San " , 31 ));
Testlist. Add ( New Person ( " Li Si " , 17 ));
Repeater1.datasource=Testlist;
Repeater1.databind ();