Find Checkbox from GridView in Content Page/Master Page

How to find a control from GridView which resides in Content Page. Here the example using to find the CheckBox, hope this will help you all...

.aspx
  1. <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">  
  2.     <asp:GridView ID="GridView1" runat="server">  
  3.         <Columns>  
  4.             <asp:TemplateField>  
  5.                 <ItemTemplate>  
  6.                     <asp:CheckBox ID="chkID" runat="server" />  
  7.                 </ItemTemplate>  
  8.             </asp:TemplateField>  
  9.         </Columns>  
  10.     </asp:GridView>  
  11. </asp:Content>  
code behind 
  1. Dim ChkSel As New CheckBox   
  2. Dim CellValue As New StringCollection   
  3. Dim tmpGV As New GridView   
  4. tmpGV = FindControlRecursive(Page.Master, "GridView1")   
  5. For i = 0 To tmpGV.Rows.Count - 1   
  6. ChkSel = DirectCast(DirectCast(tmpGV.Rows(i), GridViewRow).Cells(0), TableCell).Controls(1)   
  7. If ChkSel.Checked = True Then   
  8. CellValue.Add(DirectCast(tmpGV.Rows(i), GridViewRow).Cells(1).Text)   
  9. End If   
  10. Next   
  11. private Control FindControlRecursive(Control root, string id)   
  12. {   
  13.     if (root.ID == id)   
  14.     {  
  15.      return root;   
  16.     }  
  17.     foreach (Control c in root.Controls)   
  18.     {  
  19.         Control t = FindControlRecursive(c, id);   
  20.         if (t != null)   
  21.         {   
  22.             return t;   
  23.         }   
  24.     }   
  25.     return null;   
  26. }