kevlause
asked on
nested gridview findcontrol not working
I have a nested gridview that I need to sum up the values of a cell in and set a label in the parent gridview based on that sum. the below code I think should do that but gridview2 always comes back as nothing. What am I missing? Why can't I use findcontrol to find gridview2?
I tried the code in gridview1.databound and in page load and still nothing...
Dim count As Integer = 0
Dim GridView2 As GridView
Dim qtyshippedLabel As Label
For Each row As GridViewRow In GridView1.Rows
qtyshippedLabel = row.FindControl("qtyshippe dLabel")
GridView2 = row.FindControl("GridView2 ")
If GridView2 IsNot Nothing Then
For Each r As GridViewRow In GridView2.Rows
count = count + r.Cells(0).Text
Next
End If
qtyshippedLabel.Text = count
count = 0
Next
I tried the code in gridview1.databound and in page load and still nothing...
Dim count As Integer = 0
Dim GridView2 As GridView
Dim qtyshippedLabel As Label
For Each row As GridViewRow In GridView1.Rows
qtyshippedLabel = row.FindControl("qtyshippe
GridView2 = row.FindControl("GridView2
If GridView2 IsNot Nothing Then
For Each r As GridViewRow In GridView2.Rows
count = count + r.Cells(0).Text
Next
End If
qtyshippedLabel.Text = count
count = 0
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That function gives me the same problem. :-(
Also Chinu1310 the label is part of gridview 1. And I'm doing a findcontrol on Gridview2 for each row of gridview1 as that is where it is nested.
Also Chinu1310 the label is part of gridview 1. And I'm doing a findcontrol on Gridview2 for each row of gridview1 as that is where it is nested.
ASKER
Got it!!! It didn't databind so there were no rows in gridview2 yet! You get the points DNT!!
Protected Sub GridView1_RowDataBound(ByV al sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs ) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim count As Integer = 0
Dim qtyshippedLabel As Label = e.Row.FindControl("qtyship pedLabel")
Dim GridView2 As GridView = CType(e.Row.FindControl("G ridView2") , GridView)
If GridView2 IsNot Nothing Then
GridView2.DataBind()
For Each row As GridViewRow In GridView2.Rows
count = count + row.Cells(0).Text
Next
End If
qtyshippedLabel.Text = count
End If
End Sub
Protected Sub GridView1_RowDataBound(ByV
If e.Row.RowType = DataControlRowType.DataRow
Dim count As Integer = 0
Dim qtyshippedLabel As Label = e.Row.FindControl("qtyship
Dim GridView2 As GridView = CType(e.Row.FindControl("G
If GridView2 IsNot Nothing Then
GridView2.DataBind()
For Each row As GridViewRow In GridView2.Rows
count = count + row.Cells(0).Text
Next
End If
qtyshippedLabel.Text = count
End If
End Sub
Glad I was able to help
like say
GridView gv = gridview1.FindControl("Grd
Than gv.Findcontrol("Sumlabel")
Than assign value to this label.
Hope it helps