Find textbox value in 2 nested gridviews

487 Views Asked by At

I have a gridview2 which is inside gridview1. gridview 2 has a textbox which i need to get the value of that text box. Usually I do like this when I need to get the value from a textbox when it's inside a single gridview:

TextBox txb = (TextBox)GridView1.SelectedRow.FindControl("TextBox1");

I want to do something similar but this time getting a value from TextBox1 which is inside gridview2 and gridview2 inside gridview1. Everything is done through TemplateField of course.

1

There are 1 best solutions below

0
On BEST ANSWER
Try this...   


 foreach (GridViewRow row in grdSubClaimOuter.Rows) 
    {
    if (row.RowType == DataControlRowType.DataRow) 
    {
        GridView gvChild = (GridView) row.FindControl("grdSubClaim");
        // Then do the same method for Button control column 
        if (gvChild != null)
        {
            foreach (GridViewRow row in gvChild .Rows) 
            {
                if (row.RowType == DataControlRowType.DataRow) 
                {

          TextBox txb = (TextBox)row.FindControl("TextBox1");
                    if (txb != null )
                    {
                        // do your work
                    }
                }
            }
        }
    }
    }