我把两个表关联后,结果在DataGrid上还是只显示表1的数据。求教各位。
注:两个表关联靠两个表中的ID字段。private void Button1_Click(object sender, System.EventArgs e)
{
DataTable T1 ,T2;
..... DataSet ds = new DataSet();
ds.Tables.Add(T1);
ds.Tables.Add(T2); DataColumn dcParent = T1.Columns["ID"];
DataColumn dcChild = T2.Columns["ID"]; DataRelation dr = new DataRelation("xxx",dcParent,dcChild);
ds.Relations.Add(dr); DataGrid1.DataSource = ds.Tables["Table1"].DefaultView;
DataGrid1.DataBind();
}

解决方案 »

  1.   

    Infragistics WebGrid,专门干这个事
      

  2.   

    web from 的datagrid和win form 的datagrid不同,在WIN FORM中,建立了两个表的关系,通过导航,它就能显示两个表了,但在WEB FORM 的DATAGRID里不行。
    如果一定要这样显示,一你可以用两个DATAGRID,自己写代码实现;二将两个表JOIN到一起,作为一个表显示出来。
      

  3.   

    请详细说一下:Infragistics WebGrid
      

  4.   

    下载一个Infragistics NetAdvantage 2004 Vol 3
    你就什么都知道了.
      

  5.   

    我就是想把两个DataTable关联后的数据并集显示在一个DataGrid
      

  6.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=54F4C732-AAE2-4135-FB1B-7B4B613BAA33是不是这个
    虽然是用Repeater实现的
      

  7.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=149E5DD7-3B32-461e-ACC6-51D1652E6746这个是DataGrid
    不过是VB
      

  8.   

    我要的是
    Table1
    ID   Column1
    1     "Love"
    2     "You"
    ---------
    Table2
    ID   Column2
    1     119
    2     110
    合并后显示在DataGrid上,希望是这样
    ID Column1 Column2
    1  "Love"   119
    2  "You"    110
      

  9.   

    用sql解决:
    select a.id,a.column1,b.column2 from a join b on a.id=b.id
      

  10.   


    DataSet ds = new DataSet();
    ds.Tables.Add(T1);
    ds.Tables.Add(T2);DataColumn dcParent = T1.Columns["ID"];
    DataColumn dcChild = T2.Columns["ID"];DataRelation dr = new DataRelation("xxx",dcParent,dcChild);
    ds.Relations.Add(dr);
    在Itemdatabound事件处理函数中
    添加:
      foreach (DataRow objRow in T1.Rows)//遍历父表每一行
    {
    DataRow[] colChildRows = objRow.GetChildRows( xxx);//取该父行的所有匹配子行(以dr做参数)     // iterate through all the matching Author records adding to the result string        
                         //遍历所有子表中匹配的行集
       foreach (DataRow objChildRow in colChildRows)
        e.Item.Cells[2].Control[0].Text += objChildRow["Column2"];
    }
        
      

  11.   

    DataRow[] colChildRows = objRow.GetChildRows( "xxx");//取该父行的所有匹配子行(以xxx关系名做参数)
      

  12.   

    上面的T1在ItemDataBound中不太好处理,该为这样:(e是...EventArgs参数)
    DataRow[] colChildRows = e.Item.DataItem.GetChildRows( "xxx");//取该父行的所有匹配子行(以"xxx"做参数)??这儿记不清了     // iterate through all the matching Author records adding to the result string        
                         //遍历所有子表中匹配的行集
       foreach (DataRow objChildRow in colChildRows)
        e.Item.Cells[2].Control[0].Text += objChildRow["Column2"];