<asp:DataGrid id=TMediaDataGrid>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DataGrid id=TLTextDataGrid DataSource="<%# Tutorial_TextTB(MedKey)%>">
</asp:DataGrid>其中MedKey为外层DATAGRID的DataKeyField值,急等如何取得

解决方案 »

  1.   

    直接在TMediaDataGrid的ItemDataBound事件里处理好了,清楚一些
    private void TMediaDataGrid_ItemDataBound(...)
    {
       if(e.Item.ItemIndex>-1)
       {
          string curID  = e.Item.Cells[0].Text;      DataGrid dg = e.Item.FindControl("TLTextDataGrid ") as DataGrid;
          dg.DataSource = ..;
          dg.DataBind();
       }
    }
      

  2.   

    需要注意的是在postback后也要执行TMediaDataGrid_ItemDataBound。否则里面的datagrid会消失
      

  3.   

    已解决,因为原来两个DATAGRID是独立的两个页面,后期变更合并到一个嵌套页面里,因为原来代码为三层结构,我不想重写代码,原来的代码是根据主键ID值输入获取DATAGRID的,因此曾想是否能象ASP那样直接获取父级主键用以获取子级所需ID,后发现不可行,变通了个方式,但效率低,等以后有时间再说吧。
    <asp:DataGrid DataSource="<%# Tutorial_TextTB(Container.ItemIndex)%>">
    public DataTable Tutorial_TextTB(int ParID)//根据父节点主键获取子节点内容
    {
        DataTable Tutorial_MediaTB = (new BLLTutorial_Media()).GetTutorial_Media_By_TLEID(Int32.Parse(Request.QueryString["TLEID"]));//调用父节点应用层
        DataRow row = Tutorial_MediaTB.Rows[ParID];
        string TMediaID=row[ComTutorial_Media.TMediaID_FIELD].ToString();
        DataTable Tutorial_TextTB = (new BLLTutorial_Text()).GetBLLTutorial_Text_By_TMediaID(Int32.Parse(TMediaID));//
        return Tutorial_TextTB;
    }