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. using FindControl in inner gridview

using FindControl in inner gridview

Scheduled Pinned Locked Moved ASP.NET
csshelp
7 Posts 3 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.
  • N Offline
    N Offline
    needhi_p
    wrote on last edited by
    #1

    Hi... I am having a child gridview in another master gridview. I am having 2 tbls that contains hyperlinks in child grid and have to bind them alternately. Now i want to find this hyperlinks in my code behind.. I tried finding this hyperlinks in child grid Databound. but it does nt even recognize child grid itself... To make u clear.. here's a part of my code protected void grdmaster_DataBound(object sender, EventArgs e) { for (int i = 0; i < grdmaster.Rows.Count; i++) { GridView grdchild = new GridView(); grdchild = (GridView)grdmaster.Rows[i].FindControl("grdchild "); grdchild .DataSource = dssubsubcat; (dssubsubcat is datatable) grdchild .DataBind(); } } protected void grdchild_DataBound(object sender, EventArgs e) { for (int i = 0, count = 0; i < dssubsubcat.Rows.Count; i++) { HyperLink hyplnksubsubcat1 = new HyperLink(); hyplnksubsubcat1 = (HyperLink)grdchild.Rows[i].FindControl("hyplnksubsubcat1"); hyplnksubsubcat1.Text = grdchild .Rows[i]["SubSubCategory_Name"].ToString(); } } But here it says cannot find grdchild... Someone plz help...

    T 1 Reply Last reply
    0
    • N needhi_p

      Hi... I am having a child gridview in another master gridview. I am having 2 tbls that contains hyperlinks in child grid and have to bind them alternately. Now i want to find this hyperlinks in my code behind.. I tried finding this hyperlinks in child grid Databound. but it does nt even recognize child grid itself... To make u clear.. here's a part of my code protected void grdmaster_DataBound(object sender, EventArgs e) { for (int i = 0; i < grdmaster.Rows.Count; i++) { GridView grdchild = new GridView(); grdchild = (GridView)grdmaster.Rows[i].FindControl("grdchild "); grdchild .DataSource = dssubsubcat; (dssubsubcat is datatable) grdchild .DataBind(); } } protected void grdchild_DataBound(object sender, EventArgs e) { for (int i = 0, count = 0; i < dssubsubcat.Rows.Count; i++) { HyperLink hyplnksubsubcat1 = new HyperLink(); hyplnksubsubcat1 = (HyperLink)grdchild.Rows[i].FindControl("hyplnksubsubcat1"); hyplnksubsubcat1.Text = grdchild .Rows[i]["SubSubCategory_Name"].ToString(); } } But here it says cannot find grdchild... Someone plz help...

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      for (int i = 0; i < grdmaster.Rows.Count; i++) { GridView grdchild = new GridView(); grdchild = (GridView)grdmaster.Rows[i].FindControl("grdchild "); grdchild .DataSource = dssubsubcat; (dssubsubcat is datatable) grdchild .DataBind(); } } if i is 0 then that row is the header. The header row will not contain the childgrid. Also, you might want to use onItemDataBound instead.

      I didn't get any requirements for the signature

      N 1 Reply Last reply
      0
      • T ToddHileHoffer

        for (int i = 0; i < grdmaster.Rows.Count; i++) { GridView grdchild = new GridView(); grdchild = (GridView)grdmaster.Rows[i].FindControl("grdchild "); grdchild .DataSource = dssubsubcat; (dssubsubcat is datatable) grdchild .DataBind(); } } if i is 0 then that row is the header. The header row will not contain the childgrid. Also, you might want to use onItemDataBound instead.

        I didn't get any requirements for the signature

        N Offline
        N Offline
        needhi_p
        wrote on last edited by
        #3

        I tried using RowDataBound of gridview & bind it only if not header row. But still my prob is same as i am finding child grid controls in child grids databound. In child grid's databound it says it cannot find child grid. Can u post me a sample of how to do this...

        J 1 Reply Last reply
        0
        • N needhi_p

          I tried using RowDataBound of gridview & bind it only if not header row. But still my prob is same as i am finding child grid controls in child grids databound. In child grid's databound it says it cannot find child grid. Can u post me a sample of how to do this...

          J Offline
          J Offline
          John Gathogo
          wrote on last edited by
          #4

          What you are trying to do does not come through clearly to me but one thing I noted is that your RowDataBound event handlers do not have a correct second argument. You have: protected void grdmaster_DataBound(object sender, EventArgs e) in place of protected void grdmaster_DataBound(object sender, GridViewRowEventArgs e). With this syntax you can easily invoke the FindControl as follows:

              protected void grdmaster\_DataBound(object sender, GridViewRowEventArgs e)
              {
                  GridView grdchild = new GridView();
                  grdchild = (GridView)e.Row.Cells\[0\].FindControl("grdchild ");
          
              }
          

          That way, you would be able to find your child gridview. Notice the use of Cells[i] in the code snippet. The controls recide in the cells (where rows and columns intersect) not on the row itself. The assumption in the snippet below is that your child grid in on first column - Cells[0]. You should modify this suitably.

          J N 2 Replies Last reply
          0
          • J John Gathogo

            What you are trying to do does not come through clearly to me but one thing I noted is that your RowDataBound event handlers do not have a correct second argument. You have: protected void grdmaster_DataBound(object sender, EventArgs e) in place of protected void grdmaster_DataBound(object sender, GridViewRowEventArgs e). With this syntax you can easily invoke the FindControl as follows:

                protected void grdmaster\_DataBound(object sender, GridViewRowEventArgs e)
                {
                    GridView grdchild = new GridView();
                    grdchild = (GridView)e.Row.Cells\[0\].FindControl("grdchild ");
            
                }
            

            That way, you would be able to find your child gridview. Notice the use of Cells[i] in the code snippet. The controls recide in the cells (where rows and columns intersect) not on the row itself. The assumption in the snippet below is that your child grid in on first column - Cells[0]. You should modify this suitably.

            J Offline
            J Offline
            John Gathogo
            wrote on last edited by
            #5

            The other thing that I need to mention is that the compilers are unforgiving. So the following line: grdchild = (GridView)grdmaster.Rows[i].FindControl("grdchild "); does not mean the same as: grdchild = (GridView)grdmaster.Rows[i].FindControl("grdchild"); Notice the space in "gridchild ".

            1 Reply Last reply
            0
            • J John Gathogo

              What you are trying to do does not come through clearly to me but one thing I noted is that your RowDataBound event handlers do not have a correct second argument. You have: protected void grdmaster_DataBound(object sender, EventArgs e) in place of protected void grdmaster_DataBound(object sender, GridViewRowEventArgs e). With this syntax you can easily invoke the FindControl as follows:

                  protected void grdmaster\_DataBound(object sender, GridViewRowEventArgs e)
                  {
                      GridView grdchild = new GridView();
                      grdchild = (GridView)e.Row.Cells\[0\].FindControl("grdchild ");
              
                  }
              

              That way, you would be able to find your child gridview. Notice the use of Cells[i] in the code snippet. The controls recide in the cells (where rows and columns intersect) not on the row itself. The assumption in the snippet below is that your child grid in on first column - Cells[0]. You should modify this suitably.

              N Offline
              N Offline
              needhi_p
              wrote on last edited by
              #6

              Thankyou... use of cells[i] wrkd...

              J 1 Reply Last reply
              0
              • N needhi_p

                Thankyou... use of cells[i] wrkd...

                J Offline
                J Offline
                John Gathogo
                wrote on last edited by
                #7

                You are most welcome

                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