473,791 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Losing Hope! FindControl of dynamic gridview not working

K B
PLEASE be patient and read this. I believe I've actually reached the end
of the Web trying to find the answer!

I have an aspx using a MasterPage with a ContentPlacehol der.

I have a datatable that I use to dynamically populate a gridview - I
have to do this in order to specify which control type to put in one of
the columns. All this works fine. I've run Trace and can clearly see
that the control.id I assigned (lblQuestionID) is there
(UniqueID: ctl00$cphMain$g v1$ctl02$lblQue stionID for the first row).
Yet...on a button click event I try to get the control value...

Dim QuestionID as String= CType(gv1.FindC ontrol("lblQues tionID"),
Label).Text

...returns "Object reference not set to an instance of an object" error.

*************** ********
This is how I load the gridview (abbreviated version):

Public Sub gv1_RowDataBoun d(ByVal sender As System.Object, ByVal e As
GridViewRowEven tArgs) Handles gv1.RowDataBoun d

If e.Row.RowType = ListItemType.It em Or e.Row.RowType =
ListItemType.Al ternatingItem Then

'put Question ID in first column
Dim lblID As New Label
lblID.ID = "lblQuestio nID"
lblID.Text = dgTable(gv1).Ro ws(e.Row.DataIt emIndex)(0)
e.Row.Cells(0). Controls.Add(lb lID)
lblID.EnableVie wState = True

I have other controls (dropdownlist, text, etc.) that I need to get the
new value of after being changed by the user. I can't get any control
values including the above example.

BTW, I tested the above FindControl syntax on a simple gridview with a
standard SqlDataSource datasource and it worked. My problem is that I
must use the dynamic controls. Also, I compared both gridview items in
Trace and they were identical right down to the UniqueIDs.

I'm begging anyone out there who could suggest a solution.

Kit

P.S. The following used to work on my old and truly missed datagrid:

QuestionID = CType(datagrid1 .Rows(i).Cells( 0).Controls(0), Label).Text
-- and I've tried variations such as Controls(2), etc.

*** Sent via Developersdex http://www.developersdex.com ***
May 25 '06 #1
0 2386

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

Similar topics

1
2787
by: Scott Lyon | last post by:
I'm maintaining (read: I didn't write it, nor do I have the time to spend to rewrite it) an application that is suddenly giving me grief. The reason I say suddenly, is because we're in the process of transitioning the server on which it runs from Microsoft Windows 2000 Server, to 2003 server (going from IIS 5 to IIS 6). This problem hasn't really occurred on the 2000 server machine, but it's happening MUCH more on the new 2003 box (not...
2
3310
by: Terry | last post by:
When launching our application with Internet Explorer already opened, but not pointing to our web server, the session variables disappear. If you open I.E. after launching our app, it works fine. It also works fine if you have the option set to 'Reuse Windows for Lauching Shortcuts' checked in the I.E. properties and launch our app from a shortcut, but it fails it you launch it from the I.E. favorites or some other method that won't take...
6
1222
by: Colleyville Alan | last post by:
I seem to recall reading somewhere that there was a keyword that allowed a variable to have data added to it without losing its contents. a = "Hi " and b = "There" myvar = a myvar = b the value of myvar after this would be "Hi There".
86
3660
by: Michael Adams | last post by:
I don't know if you have noticed, but it seems like Microsoft is losing interest in C#, and putting their energy into Visual Basic.NET instead. For instance, online chats by language since July 1, 2004: VB.NET 47 C# 6 C++ 8 J# 0
4
2171
by: Stephen | last post by:
I have a .NET (1.1 framework) application that is losing a session variable on only a few PC's. The main page is loading up in a frame in a Portal application. On the Page_Load it stores an object with the user id and password into the session. The web page includes a set of links. When the user clicks on a link, another page within this application is opened in a new window. On the Page_Load of this second page, I am retrieving...
5
5294
by: fbwhite | last post by:
I know this issue has been brought up many times, but I have tried many of the solutions to no avail. I wanted to give my specific case to see if someone could be of any help. We are using the sessionstate inproc mode and users are randomly losing their session. I do not believe it is happening across all users at one time. It seems to happen to different users at different times, but I am only going off heresay. The aspnet worker...
9
4163
by: UJ | last post by:
I have a page where the user can make changes to some DB stuff. It's not saved until they hit the save button. I'd like to have it so that if they attempt to navigate somewhere else, I give them a warning (and preferably the ability to stop them) if they don't want to lose their changes. In other words - an 'Are you sure you want to do this?' message box. Can anybody help me on how to do this? TIA - J.
9
2547
by: Adrian Parker | last post by:
We have a website that works everywhere but on a few PCs on this one site.. Asp.Net 1.1 Server = Windows 2003 Client = XP In the web.config we use - cookieless="false" in the browser settings they have "Always allow session cookies" set to true When the browser connects to the website the first page sets a session variable called "user_ref" to something and then calls another page. If on
7
3561
by: DaTurk | last post by:
Hi, I'm trying to send a large number of messages to a UDP multicast group with which I have one client subscribed. But I'm losing mesages, and I'm not entirely sure why. I can't seem to find the reason, the asynch receive on the client doesn't even get called the corect number of times, which is 1000. I'm trying to send 1000 messages via an asynch call to sendto. the connect code for the send
3
1792
by: David C | last post by:
I have an aspx page that has HyperLink controls that have NavigateURL set to the current page. I was assuming that would postback but it comes back like the first time in the page and I am losing values in one of my TextBox controls. It is there when I first load the page from another page but gets lost as soon as I click the HyperLink. What am I missing? Thanks. David
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.