using FindControl in inner gridview
-
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...
-
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...
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
-
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
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...
-
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...
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 ofprotected 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.
-
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 ofprotected 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.
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 ". -
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 ofprotected 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.
-
You are most welcome