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. Fetch Parent Gridview Row index on Child gridview delete row ?

Fetch Parent Gridview Row index on Child gridview delete row ?

Scheduled Pinned Locked Moved ASP.NET
databasequestion
3 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.
  • Z Offline
    Z Offline
    zeego
    wrote on last edited by
    #1

    Hi I have nested gridviews bounded to data tables. On child gridview delete event I'm trying to fetch the parent gridview row index somehow to fetch the child gridview through find control and databind it to show the updated changes. However I am fetching the the wrond index through my code as its returning the row number of the child and not the parent. Here's my row delete event for the child. :omg: protected void gvSec_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridView gvtmp = (GridView)gvComp.Rows[e.RowIndex].FindControl("gvSec"); DataTable tmpdt = (DataTable)ViewState["SecTab"]; if(tmpdt!=null) { tmpdt.Rows.RemoveAt(e.RowIndex); } gvtmp.DataSource = tmpdt; gvtmp.DataBind(); ViewState["SecTab"]=tmpdt; }

    L 1 Reply Last reply
    0
    • Z zeego

      Hi I have nested gridviews bounded to data tables. On child gridview delete event I'm trying to fetch the parent gridview row index somehow to fetch the child gridview through find control and databind it to show the updated changes. However I am fetching the the wrond index through my code as its returning the row number of the child and not the parent. Here's my row delete event for the child. :omg: protected void gvSec_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridView gvtmp = (GridView)gvComp.Rows[e.RowIndex].FindControl("gvSec"); DataTable tmpdt = (DataTable)ViewState["SecTab"]; if(tmpdt!=null) { tmpdt.Rows.RemoveAt(e.RowIndex); } gvtmp.DataSource = tmpdt; gvtmp.DataBind(); ViewState["SecTab"]=tmpdt; }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try the following code. You can get the parent GridView row by ((GridView)sender).Rows[e.RowIndex].Parent.Parent.Parent.Parent Also you can get the control or cells value of the parent gridview using ((GridView)sender).Rows[e.RowIndex].Parent.Parent.Parent.Parent.Controls[0] collection

      Z 1 Reply Last reply
      0
      • L Lost User

        Try the following code. You can get the parent GridView row by ((GridView)sender).Rows[e.RowIndex].Parent.Parent.Parent.Parent Also you can get the control or cells value of the parent gridview using ((GridView)sender).Rows[e.RowIndex].Parent.Parent.Parent.Parent.Controls[0] collection

        Z Offline
        Z Offline
        zeego
        wrote on last edited by
        #3

        Thanks for the reply Mr. Ramesh. :) It solved my problem, can you please explain a little how this Parent.Parent works ? I mean logically . ((GridView)sender).Rows[e.RowIndex].Parent.Parent.Parent.Parent How does .NET drill down the parent by using this parent property/method ? Thanks, Mike.

        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