通过ds.Relations[0].ChildTable. 
不能访问吗?如得到行
ds.Relations[0].ChildTable.Rows[i]

解决方案 »

  1.   

    我只是想得到子表中的数据,现在是得到了,但当我更换父表中的记录时就发生了错误。
    现在他还是傻呼呼的去给我取第一个记录.也就是说,当更换的时候我还是无法得到我想要的哪一行
    代码如下:
    int curow=dataGrid2.CurrentCell.RowNumber;//得到当前行数
    DataRow data= this.dataSet11.Relations[0].ChildTable.Rows[curow];
    string str=data["foodname1"].ToString();
    MessageBox.Show(str);其实我也知道我错在那里了。就是写注释的哪一行,
    我不该用dataGrid2的当前行数去指定数据库里的行数可是不这样做我该怎么做呢?
      

  2.   

    用前台脚本可以获得,很难表达清楚,提醒一下吧,grid在前台被解释为《table》标签,所以取得你要的行的rows.cells[……]就可以了,下面是给grid的行添加前台事件的代码,你应该用的着
    ----------------------------------
     if( e.Item.ItemIndex != -1 )
    {
    e.Item.Attributes.Add("onmouseover", "this.bgColor='#C1D2EE'");
    e.Item.Attributes.Add("onclick", 
    "document.all.myBox.innerText=this.cells[1].innerText;");//document.all.form1.city.value=this.cells[0].innerText;");
    if (e.Item.ItemIndex % 2 == 0 )
    {
    e.Item.Attributes.Add("bgcolor", "#FFFFFF");
    e.Item.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('myGrid').getAttribute('singleValue')");
    }
    else
    {
    e.Item.Attributes.Add("bgcolor", "oldlace");
    e.Item.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('myGrid').getAttribute('oldValue')");
    }
    }