Summaryto find child controls That area located in Template of a pent control, you can use the
FindControl method or the
Cells Collection Index. However, The
TemplateColumn column and the
BoundColumn Column Are Different When You Try To Use
FindControl method or the
Cells Collection Index To Reference A Particular Control in The Cells of a Parent Control.
. In a BoundColumn column, the cell always contains a single control Therefore, you can use 0 as the index For example, 0 is the index in the following code:. String ProductName = ((TextBox) e.Item.Cells [3] .Controls [0]) Text;. In a TemplateColumn column, the controls are interspersed with literal controls Therefore, the previous blank space makes up a literal control In this case, the FindControl method must be used with the ControlID parameter as shown.. In The Following Code: Bool Discon = ((Checkbox) E.Item.FindControl ("ControlID")). Checked; Note The Control Pableholder is the id of the control.
More inforationto use the the
FindControl method or the
Cells Collection Index To Find A Child Control in a Parent Control, Follow these Steps:
Start Microsoft Visual Studio .NET Create a new Microsoft ASP.NET Web application project that is named FindControl by using Microsoft Visual C # .NET. By default, WebForm1.aspx is created. To add a DataGrid control to the WebForm1.aspx page, replace the existing code with the following code: <% @ Page language = "c #" Codebehind = "WebForm2.aspx.cs" AutoEventWireup = "false" Inherits = "FindControl.WebForm2"%>