. NET data source (datasource)

Source: Internet
Author: User
. 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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.