数据源为一个list列表
格式为
int a
string b
product c(product是一个类,类又有很多属性)
现在是a和b绑定没问题,但是c却不行,比如c有属性d,在数据列名称输入c.d则找不到数据,请问该如何绑定? 
记得在asp.net中的gridview中,绑定的方法挺简单的:
<%#c.d%>就行了,但是在winfrom开发中一直找不到此种方法,望记人解答。

解决方案 »

  1.   

    最后一句错了,是
    <%#Eval('c.d')%>就行了
      

  2.   

    楼主可以改为用下面的方法邦定数据:
    this.gridview.Rows.Add(
                                count++,
                                archiveInfo.Id,
                                archiveInfo.AID,
                                archiveInfo.EDocId,
                                archiveInfo.Title,
                                archiveInfo.ArchiveType,
                                archiveInfo.QZID,
                                archiveInfo.YearId,
                                archiveInfo.ArchiveSize,
                                archiveInfo.TableName,
                                archiveInfo.TableId,
                                archiveInfo.PackageNo,
                                archiveInfo.ColNo,
                                archiveInfo.StandardPackageNo
                                );
    //archiveInfo是一个实体类在这之前用如下方法为gridView添加列:
    this.gridView.Columns.Add("Number","编号");
                this.Columns.Add("Id", "序号");
                this.Columns.Add("aid", "原档号");
                this.Columns.Add("edocid", "电子档号");
                this.Columns.Add("Title", "题名");
                ............
      

  3.   

    在asp.net中没那么麻烦,我现在用的是winfrom编程,谢谢三楼,方法不行
      

  4.   

    在 WinForm 中:private List<ProductModel> lpm;    lpm=GetProducts();   //访问数据库this.DataGridView1.DataSource= lpm;
      

  5.   

    Jinwmmail() ( ) 信誉:100    Blog   加为好友 
    你这个能绑定,但是我现在要绑定的数据是类再包含类
    private List<ProductModel> lpm;
    Private ProductModel.otherclass
    otherclass又有若干个属性...
      

  6.   

    我说详细一些...
    在表示层文件
    DataGridView1.DataSource = GetData();我现在要实现的是将
    Class1.Mystring
    Class1.Class2.Mystring
    Class2.Class2.MyInt
    显示出来,在同一个DataGridView1下面显示,
    类型和方法定义如下:在BLL和DAL层文件
    public List<Class1> GetData()
    {
       List<Class1> class1 = new List<Class1>;
    ...连数据
       using (IdataReader dr = db.ExecuteReader(dbCommand))
       {
          while (dr.Read())
          {
            class1.add(new Class1(mystring));
          }
       }//这里填充数据
       foreach (Class1 test in class1)
       {
       class1.Class2 = GetClass2();//这里将将充Class1下的Class2(一个类属性)数据
       }
    }Model层
    Class1文件
    private string _MyString;
    public string Mystrign
    {
    get {return _MyString;}
    set {_MyString = value;}pviate Class2 _Class2;//这是一个类
    public Class2 Class2
    {
    get {return _Class2}
    set {_Class2 = value;}
    }
    Class2文件
    private string _MyString;
    public string Mystrign
    {
    get {return _MyString;}
    set {_MyString = value;}private string _MyInt;
    public string MyInt
    {
    get {return _MyInt;}
    set {_MyInt= value;}