FindControl()和嵌套控件

时间:2012-02-21 11:28:12

标签: c# asp.net reflection ext.net

我有这个ASP代码:

 <ext:GridPanel ID="grid">
                <ColumnModel runat="server">
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column Align="Center" ColumnID="Type">
                        </ext:Column>
                    // closing tags

我想获取columns对象。我正在尝试这个:

var typeCol= this.grdResourceState.ColumnModel.Columns.Where(column => column.ColumnID == "Type"); // this works
var typeColRef= FindControl("grdResourceState.ColumnModel.Columns"); // this is a null

如何让FindControl能够搜索控制孩子?

1 个答案:

答案 0 :(得分:0)

您应该为 ColumnModel 控件分配一个ID,然后检索if。一旦你得到它,你可以访问儿童控件:

<ext:GridPanel ID="grid">
                <ColumnModel runat="server" id="someId">
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column Align="Center" ColumnID="Type">
                        </ext:Column>
                    // closing tags

然后:

var typeCol= this.grdResourceState.ColumnModel.Columns.Where(column => column.ColumnID == "Type"); // this works
var typeColRef= FindControl("someId");

Here's more info on the FindControl method