DataSource的数据源

it2026-09-01  4

使用DataSource属性指定要绑定到数据列表控件的值的源。

数据源必须是实现System.Collections.IEnumerable接口(例如System.Data.DataView、system.Collections.ArrayList或System.Collections.Hashtable)

               或IListSource接口的对象。(如:dataset,datatable,dataview)

1、List<T>数据源

  

List List<string> li=new List<string>(); For(int i=0;i<=10;i++) { li.add(i.tostring()); } xxxx.DataSource=li; xxxx.DataBind();

 

List<类> 自定义一个类 public class MyClass { public MyClass() { // // TODO: 在此处添加构造函数逻辑 // } private string _Name; private string _Home; public string Name { set { _Name = value; } get { return _Name; } } public string Home { set { _Home = value; } get { return _Home; } } } List<MyClass> li=new List<MyClass>(); For(int i=0;i<=10;i++) { MyClass cl=new MyClass(); cl.Name=i+"Name"; cl.Home=i+"Home"; li.Add(cl); } DropDownList1.DataSource=li; DropDownList1.DataTextField="Name"; DropDownList1.DataBind();

 

 

转载于:https://www.cnblogs.com/wupeiqi/archive/2013/03/10/2953263.html

最新回复(0)