首页 > 解决方案 > Getting Eval value from parent Data control

问题描述

I have a DetailsView with a TemplateField that contains a GridView.

When using Eval inside the GridView cells, I only get access to the data source of the GridView.

How can I access the data of the parent, i.e. the DetailsView?

Thank You

<asp:DetailsView ID="det1" DataSourceID="source1">
 <asp:TemplateField>
   <ItemTempalte>
     <asp:GridView ID="grid1" DataSourceID="source2">
     <Columns>
       <asp:TemplateField>
         <ItemTempalte>
          //this is where I need a column from source1 while Eval only gives me source2
          <asp:Label Text='<%# Eval("column from source1") %>'/>
         </ItemTempalte>
       </asp:TemplateField>
     </Columns>
    </asp:GridView>
  </ItemTempalte>
 </asp:TemplateField>
</asp:DetailsView>

标签: asp.net

解决方案


跳过怎么样Eval()。尝试这样的事情

<asp:Label Text='<%# CType(source1.DataItem, System.Data.DataRowView)("column from source1") %>' />

您可能需要检查对象是否为Source1,以查看其DataItem是否为DataRowView或其他类型。我在你定义的地方看不到你的代码source1,所以我只能提供我最好的猜测。


推荐阅读