DataGrid.FindControl() returns nothing

M

MattB

I've got some controls (mostly textboxes for now) that get created at
runtime in a DataGrid. I create them using the OnItemDataBound event. I
realize this isn't ideal, but I'm trying to see if I can make this work
anyway.

In a button click event I loop through the dataset the datagrid is bound
to and try to use FindControl to get at my controls. Below is a snippet
from the button click event:

iRow = 0
For Each dr In dtGfields.Rows
strCol = dr("ColName")
theCell = dgGuest.Items(iRow).Cells(1)
Select Case strCol
...
Case Else
tb = theCell.Controls(0)
'dgGuest.FindControl(strCol)
If UCase(dr("val")) <> UCase(tb.Text) Then
xml = wwSales.EZTag(strCol, UCase(tb.Text))
End If
End Select
...
iRow += 1
Next

I've tried a bunch of different approaches with FindControl but I always
wind up with a return value of Nothing. Can anyone see anything here
that I'm doing wrong? I initially started out with using it like this:

tb = dgGuest.FindControl(strCol)

TIA!
Matt
 
W

Wilco Bauwer

FindControl will only search for a control with the specified ID within
the naming container of the control on which you called FindControl.
You will have to narrow the search by getting to the container of the
control you are looking for first.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top