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