引用嵌套控件 [英] Referencing nested control
本文介绍了引用嵌套控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个 gridviews - 一个嵌套在另一个中 - 我试图以编程方式设置子网格的数据源,但我不确定如何引用它.
I have two gridviews - one nested in the other - and I am trying to set the datasource of the child grid programmaticly, but am not sure how to reference it.
<telerik:RadGrid ID="RadGridResults" runat="server" AutoGenerateColumns="true" OnNeedDataSource="RadGridResults_NeedDataSource">
<MasterTableView>
<NestedViewTemplate>
<telerik:RadGrid ID="RadGridDetails" runat="server" AutoGenerateColumns="true">
</telerik:RadGrid>
</NestedViewTemplate>
</MasterTableView>
</telerik:RadGrid>
我已经试过了:
RadGrid radGridDetails = RadGridResults.FindControl("RadGridDetails") as RadGrid;
radGridDetails.DataSource = myList.ToList();
但这会返回 NullReferenceException.
But this returns a NullReferenceException.
有人可以告诉我如何做到这一点吗?
Can someone please show how I can accomplish this?
推荐答案
直接对集合进行数据绑定即可:
Just databind the collection directly:
<telerik:RadGrid ID="RadGridDetails" runat="server" AutoGenerateColumns="true"
DataSource='<%# Eval("myList") %>'>
</telerik:RadGrid>
这篇关于引用嵌套控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文