Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 0.92 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to find all controls in Gridview?
  2. TextBox txtItem = (TextBox)Grid1.Rows[Grid1.EditIndex].FindControl("txtItem");
  3.        
  4. foreach(Control c in Grid1.Rows[Grid1.EditIndex].Controls)
  5. {
  6.     // do stuff in here.
  7.  
  8. }
  9.        
  10. function edit(this)
  11. {
  12.    var textboxID = $(this).parent().find("[id$='textBoxId']");
  13. }
  14.        
  15. foreach ( GridViewRow row in MyGridView.Rows )
  16. {
  17.     TextBox myTextBox = (TextBox)row.FindControl("myTextBox");
  18. }
  19.        
  20. var listOfControls = Utility.FindControlsOfType<TextBox>(yourGridRow);
  21.        
  22. public static class Utility
  23. {    
  24.     public static List<T> FindControlsOfType<T>(Control ctlRoot)
  25.     {
  26.         List<T> controlsFound = new List<T>();
  27.  
  28.         if (typeof(T).IsInstanceOfType(ctlRoot))
  29.             controlsFound.Add((T)(object)ctlRoot);
  30.  
  31.         foreach (Control ctlTemp in ctlRoot.Controls)
  32.         {
  33.             controlsFound.AddRange(FindControlsOfType<T>(ctlTemp));
  34.         }
  35.  
  36.         return controlsFound;
  37.     }
  38. }