Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Search Control in GridView in asp.net

Search Control in GridView in asp.net

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-nettutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anish27patel
    wrote on last edited by
    #1

    Hello All, I need to search recursive control inside gridview i have written below code but i can not able to find the control in which are define in I have taken on linkbutton inside templated field but when i try to search control but i didn't get. Code : public static Control FindControlRecursive(Control Root, string Id) { if (Root.ID == Id) return Root; foreach (Control Ctl in Root.Controls) { Control FoundCtl = FindControlRecursive(Ctl, Id); if (FoundCtl != null) return FoundCtl; } return null; } but it return null while i am try to find out control like LinkButton B = FindControlRecursive(GridView1, "lnk") as LinkButton; can you please help how to resolved above issue? Thanks in advance,

    Anish Patel

    P 1 Reply Last reply
    0
    • A anish27patel

      Hello All, I need to search recursive control inside gridview i have written below code but i can not able to find the control in which are define in I have taken on linkbutton inside templated field but when i try to search control but i didn't get. Code : public static Control FindControlRecursive(Control Root, string Id) { if (Root.ID == Id) return Root; foreach (Control Ctl in Root.Controls) { Control FoundCtl = FindControlRecursive(Ctl, Id); if (FoundCtl != null) return FoundCtl; } return null; } but it return null while i am try to find out control like LinkButton B = FindControlRecursive(GridView1, "lnk") as LinkButton; can you please help how to resolved above issue? Thanks in advance,

      Anish Patel

      P Offline
      P Offline
      PunkIsNotDead
      wrote on last edited by
      #2

      Hi! in future post, try using the code block :-D just for better understanding of the code :thumbsup: Well, the Control, must be a GridView, so you can add

      public static Control FindControlRecursive(Control Root, string Id)
      {
      if (Root.ID == Id)
      return ((GridView)Root);
      if (Root is GridView)//or some like that (i don't remember well)
      {
      GridView gv = ((GridView)Root);
      Int32 num = 3;//Based zero, number of column where is the link button column
      Int32 row = 1;//Based zero, number of row where is the link button row
      Control FoundCtl = ((Control)gv.Rows[row].Cells[num].FindControl(Id));
      if (FoundCtl != null)
      return FoundCtl;
      }
      return null;
      }

      Remember that in ASP.NET the dinamically controls added like in grid view Template field, have the same name, except in Client-Side. if you want a especific row, you only need to change the row parameter ;)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups