473,385 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DataGrid.FindControl() returns nothing

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
Nov 19 '05 #1
2 11167
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.

Nov 19 '05 #2
Hi Matt:

You'll want to call FindControl on the rows of the DataGrid and not
the DataGrid itself. A DataGrid row is a DataGridItem.

I have some samples in C# here:
http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 15 Feb 2005 15:32:55 -0700, MattB <so********@yahoo.com>
wrote:
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


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Deane | last post by:
Has anyone had experience with "function_exists" not finding a function that you KNOW you've defined? I have defined a function we'll call "foo": 1. I know that function has been parsed, because...
7
by: Danny | last post by:
Newbie here Thanks for the help with this command: print "Status: 204 No Content\n\n"; which returns nothing in a perl script. This is great because I just want my perl script to increment a...
1
by: James G. Beldock | last post by:
I have seen the following behavior: when issuing a Page.FindControl() for a control which exists in an item template (from within an ItemDataBound() event, for example), I get nulls back...
2
by: Dave | last post by:
Hi all, Does anyone know how to find a control in a DataGrid Footer by using DataGrid.FindControl etc?
3
by: Sven | last post by:
Hello, I am trying to store an object and its type in a database table as text and then restore the object to its original form. I have created a couple of functions to help me with this: ...
0
by: S. B | last post by:
Hello all, I have some trouble with the following code snippet that is at the end of the post. The function is supposed to browse all members from a form or a user control to find all menuitems....
8
by: Sam | last post by:
Hi, Here is my code : For Each row As DataRow In m_dsTabs.Tables(0).Rows If CInt(row("TabId")) = DirectCast(tabQryTabs.SelectedTab, QueryTabPage).TabId Then...
0
by: jyuan | last post by:
Hi, I have two dropdownlist template columns in datagrid. Once the first one (Test Type, in column index 2, ID="ddlTestTypeID") selection changed, I need to re-bound the second dropdownlist (test...
1
by: Sand Yaah | last post by:
i went thru a discussion put by eros and helped out by dmjpros. d questions asked were right and i tried each but there was no problem there. my code returns null in xmlHttp.responseXML and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.