FindControl in GridView

B

Bruno Alexandre

Hi guys,

I have this code:

Dim gv As GridViewRow
Dim str As String = ""
Dim dd As DropDownList

For Each gv In gvItems.Rows
If gv.RowType = DataControlRowType.DataRow Then
str &= gv.RowType.ToString & "<br/>"
dd = CType(gvItems.FindControl("dd1"), DropDownList)
If dd IsNot Nothing Then
str &= "found"
End If
End If
Next

and I can't get into str &= "found"
it doesn't find the control... What I'm doing wrong? the control is showed
in the page! and has the id = "dd1"


Any help?... please.
 
G

Guest

surely this line:

dd = CType(gvItems.FindControl("dd1"), DropDownList)

should read

dd = CType(gv.FindControl("dd1"), DropDownList)

If you want it to look for the control dd1 on each row in the loop.
 
B

Bruno Alexandre

got that 2 seconds after post the message, but still wont work, then I tried
again (for the 100th time) search the internet finding a solution and here
it is:

Dim gv As GridViewRow
Dim str As String = ""

For Each gv In gvItems.Rows
If gv.RowType = DataControlRowType.DataRow Then
Dim dropDownListText As String = CType(gv.FindControl("qty"),
DropDownList).SelectedItem.Value
Dim CheckBoxChecked As Boolean = CType(gv.FindControl("rem"),
CheckBox).Checked
If CheckBoxChecked Then
str &= dropDownListText & "<br/>"
End If
End If
Next

I dont know why, but I need to change the names :-(

But now it works perfectly :) ... I'm so happy!!! it took me 2 days to get
an answer :-/
but know I can help other with the same question ;-)
 
Joined
Jul 31, 2006
Messages
2
Reaction score
0
Gridview help

I am havin dridview in pannel.i am able to find gridview through findconrol but not able to find ineer controls of gridview through findcontrol.


panel = pannellstages
gridview = Gv_PromotionStages
checkbox = check

Code is as follows

Dim gv As GridViewRow
Dim str As String = ""

For Each gv In Gv_PromotionStages.Rows
If gv.RowType = DataControlRowType.DataRow Then
chk1 = CType(gv.FindControl("check"), CheckBox)

Dim CheckBoxChecked As CheckBox = CType(pannellstages.FindControl("Gv_PromotionStages").FindControl("check"), CheckBox)
End If

Next
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top