引用嵌套控制 [英] Referencing nested control

查看:125
本文介绍了引用嵌套控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个GridView的 - 一个嵌套在其他的 - 和我想programmaticly设置子网格的数据源,但我不知道如何引用它

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>

我已经试过这样:

I have tried this:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆