//先看看FindControl的源码
protected virtual Control FindControl(string id, int pathOffset) { string str; this.EnsureChildControls(); if (!this.flags[0x80]) { Control namingContainer = this.NamingContainer; if (namingContainer != null) { return namingContainer.FindControl(id, pathOffset);//向上递归 } return null; } if (this.HasControls() && (this._occasionalFields.NamedControls == null)) { this.EnsureNamedControlsTable(); } if ((this._occasionalFields == null) || (this._occasionalFields.NamedControls == null)) { return null; } char[] anyOf = new char[] { '$', ':' };//name,id int num = id.IndexOfAny(anyOf, pathOffset); if (num == -1)//不再存在父控件(容器)时,获得该查找ID的控件 { str = id.Substring(pathOffset); return (this._occasionalFields.NamedControls[str] as Control); } str = id.Substring(pathOffset, num - pathOffset);//否则,继续寻找父控件(容器),调用其FindControl方法 Control control2 = this._occasionalFields.NamedControls[str] as Control; if (control2 == null) { return null; } return control2.FindControl(id, num + 1);//pathOffset往上一级 }
//再看GridView列
<asp:GridView ID="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound" Width="1680px">
<Columns>
<asp:TemplateField HeaderText="编码">
<ItemTemplate>
<asp:Literal ID="Literal1" runat="server" Text='<%# eval_r("ID") %>' Visible="false"></asp:Literal>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# eval_r("ID", "Edit.aspx?Id={0}") %>' Text='<%# eval_r("ID") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FindDeptName" HeaderText="发现单位" >
<ItemStyle Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="FindUserName" HeaderText="发现人" >
<ItemStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="FindWay" HeaderText="发现方式" >