zoukankan      html  css  js  c++  java
  • .net数据源(DataSource)

    .net中:
    DropDownList,ListBox,CheckBoxList,RodioButtonList等控件的.DataSource属性可使用
    ListItemCollection集合,注意:绑定时须指定DataValueField,DataTextField属性的值!
    不指定字段后value和Text的值都为Text.

    ListItemCollection listItems = new ListItemCollection();
    listItems.Add(
    new ListItem("测试数据一""1"));
    listItems.Add(
    new ListItem("测试数据二""2"));
    RadioButtonList1.DataSource 
    = listItems;
    /*指定字段值,不指定默认为:
    RadioButtonList1.DataValueField = "Text";
    RadioButtonList1.DataTextField = "Text";
    */
    RadioButtonList1.DataValueField 
    = "Value";      //指定控件Value字段值
    RadioButtonList1.DataTextField = "Text";        //指定控件Text字段值
    RadioButtonList1.DataBind();

    数据控件:Repeater,DataList,DetailView,GridView等都可以直接绑定数据源为泛型数据,如:
    List<>,实现IList<>接口数据。
    public class person
    {
        
    private string name;
        
    private int age;

        
    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;
        }
    }
    //使用数据控件:
    IList<person> testList = new List<person>();
    testList.Add(
    new person("张三",31));
    testList.Add(
    new person("李四",17));

    Repeater1.DataSource 
    = testList;
    Repeater1.DataBind();



  • 相关阅读:
    typescript 深层次对象内层(N)转外层(N),支持多层级递归转换,多应用于多语言数据结构转换
    js 柯里化、深拷贝、浅拷贝
    js IntersectionObserver api
    javascript-state-machine
    NodeJs的CommonJS模块规范
    js 动画
    【THUPC 2018】赛艇
    【CF528D】Fuzzy Search
    【UR #6】懒癌
    【HNOI 2019】JOJO
  • 原文地址:https://www.cnblogs.com/ywkpl/p/987753.html
Copyright © 2011-2022 走看看