zoukankan      html  css  js  c++  java
  • Gridview的数据源可为dataview,dataset,datatable,list 等,只要符合Ilist 结口的数据集合.

    Gridview的数据源可为dataview,dataset,datatable,list 等,只要符合Ilist 结口的数据集合.

    前几种没什么可说的,重要的是list这个东西并不常用.
    当list做为gridview的数据源时必须存储的是一组对象的集合.

    常见错误
    ID 为“GridView1”的 GridView 的数据源没有任何可用来生成列的属性或特性。
    原因和解决办法
    造成此错误的源因是,对象中的属性不是可读写的.只要把对对象的属性改为可读写的就行了.其绑定试和dataset 一样.
    下面的例子:

    //类文件
    ublic class StudentInfo
    {
        private int _stuid;
        private string _sname;
        private int _sage;

     public StudentInfo()
     {
      //
      // TODO: 在此处添加构造函数逻辑
      //
     }
        public int StuId
        {
            get { return _stuid; }
            set { _stuid = value; }
        }

        public string Sname
        {
            get { return _sname; }
            set { _sname = value; }
        }
        public int Sage
        {
            get { return _sage; }
            set { _sage = value; }
        }
    }

    //绑定方法
     private void gvBind()
        {
            List<StudentInfo> list = new List<StudentInfo>();
            StudentInfo aa = new StudentInfo();
            aa.StuId = 1;
            aa.Sname = "aa";
            aa.Sage = 20;
            StudentInfo bb = new StudentInfo();
            bb.Sage = 21;
            bb.Sname = "bb";
            bb.StuId = 2;
            StudentInfo cc = new StudentInfo();
            cc.StuId = 3;
            cc.Sname = "cc";
            cc.Sage = 23;
            list.Add(aa);
            list.Add(bb);
            list.Add(cc);
            GridView1.DataSource = list;
            GridView1.DataBind();
        }

  • 相关阅读:
    ASP.NET编程的十大技巧
    C#学习心得(转)
    POJ 1177 Picture (线段树)
    POJ 3067 Japan (树状数组)
    POJ 2828 Buy Tickets (线段树)
    POJ 1195 Mobile phones (二维树状数组)
    HDU 4235 Flowers (线段树)
    POJ 2886 Who Gets the Most Candies? (线段树)
    POJ 2418 Cows (树状数组)
    HDU 4339 Query (线段树)
  • 原文地址:https://www.cnblogs.com/wenming205/p/1241166.html
Copyright © 2011-2022 走看看