Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello experts,
I have a gridview inside a gridview. means I have a master view which have child gridview inside. Now i have a link button in child gridview. my problem is how i find master gridview row index when i click link button of child grid view.

Thanks
Posted
Updated 15-May-18 23:47pm
v4

I have find solution.........
C#
GridViewRow Gv2Row = (GridViewRow)((LinkButton)sender).NamingContainer;       
        GridView Childgrid = (GridView)(Gv2Row.Parent.Parent);       
        GridViewRow Gv1Row = (GridViewRow)(Childgrid.NamingContainer);
        int b = Gv1Row.RowIndex;
 
Share this answer
 
v2
add below code for your child GridView.
C#
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "go")
        
          {

        GridViewRow Gv2Row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
        GridView Childgrid = (GridView)(Gv2Row.Parent.Parent);
       
        GridViewRow Gv1Row = (GridViewRow)(Childgrid.NamingContainer);
        GridView Parentgrid = (GridView)(Gv1Row.Parent.Parent);
        
       foreach (GridViewRow Grid1row in Parentgrid.Rows)
        {
            Label lbl = (Label)(Grid1row.FindControl("Label1"));
            string grid2Rowtext = lbl.Text;
            Response.Write(grid2Rowtext + "<br>");

        }
    }
}
 
Share this answer
 
v2
Comments
ErBhati 28-Mar-14 5:46am    
Thanks for ur solution ...........

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900