473,404 Members | 2,178 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,404 software developers and data experts.

findcontrol

I have a page on which several dropdownlists are placed dynamically.
So, sometimes there are no ddl's and sometimes there a are let's say 10
ddl's.

These ddl's are created in my code.

Now, that is no problem. The problem is that when I want to INSERT values
INTO a table in my database, I should be able to get the value of the
selecteditem of the dropdowns.
And as these controls are not realy on the page, I always get an error.
(object reference not set to an instance of an object)

I tried several combinations with findcontrol, but nothing works...

Any help is appreciated ! THX

Here is 1 of my tries:

############# code ########
if txt_counter.text > 0 then 'this tells me how
much dropdownlists were created on page load (they were named: dd_1, dd_2,
etc)

Dim counter as integer

for counter=1 to txt_counter.text

Dim mydropdown1 As dropdownlist =
Page.FindControl("dd_" & counter)

If Not mydropdown1 Is Nothing Then

'insert the listproductoptions
Dim dbComm1 As New SQLCommand()
dbComm1.CommandType = CommandType.Text
dbComm1.CommandText = "INSERT INTO
tbl_listproductsoptions(listproductID, optionID) VALUES (@listproductID,
@optionID)"
dbComm1.Connection = MyConnection

dbComm1.Parameters.Add("@listproductID",SqlDbType. int)

dbComm1.Parameters.Add("@optionID",SqlDbType.int)
dbComm1.Parameters("@listproductID").Value =
intNewID
dbComm1.Parameters("@optionID").Value =
mydropdown1.selecteditem.value
'MyConnection.Open()
dbComm1.ExecuteScalar()

end if

counter = counter + 1

Next

end if
Nov 19 '05 #1
1 1051
problem solved.

request.form("dd_" & counter)

"nicholas" <mu********@hotmail.com> wrote in message
news:eq**************@TK2MSFTNGP14.phx.gbl...
I have a page on which several dropdownlists are placed dynamically.
So, sometimes there are no ddl's and sometimes there a are let's say 10
ddl's.

These ddl's are created in my code.

Now, that is no problem. The problem is that when I want to INSERT values
INTO a table in my database, I should be able to get the value of the
selecteditem of the dropdowns.
And as these controls are not realy on the page, I always get an error.
(object reference not set to an instance of an object)

I tried several combinations with findcontrol, but nothing works...

Any help is appreciated ! THX

Here is 1 of my tries:

############# code ########
if txt_counter.text > 0 then 'this tells me how much dropdownlists were created on page load (they were named: dd_1, dd_2,
etc)

Dim counter as integer

for counter=1 to txt_counter.text

Dim mydropdown1 As dropdownlist =
Page.FindControl("dd_" & counter)

If Not mydropdown1 Is Nothing Then

'insert the listproductoptions
Dim dbComm1 As New SQLCommand()
dbComm1.CommandType = CommandType.Text
dbComm1.CommandText = "INSERT INTO
tbl_listproductsoptions(listproductID, optionID) VALUES (@listproductID,
@optionID)"
dbComm1.Connection = MyConnection

dbComm1.Parameters.Add("@listproductID",SqlDbType. int)

dbComm1.Parameters.Add("@optionID",SqlDbType.int)
dbComm1.Parameters("@listproductID").Value = intNewID
dbComm1.Parameters("@optionID").Value =
mydropdown1.selecteditem.value
'MyConnection.Open()
dbComm1.ExecuteScalar()

end if

counter = counter + 1

Next

end if

Nov 19 '05 #2

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

Similar topics

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: christof | last post by:
How to do it: My page: <asp:DataList ID="dataListRoleMembers" ...> .... <FooterTemplate> <asp:LinkButton ID="btnAddMember" runat="server"...
2
by: encoad | last post by:
Hi everyone, I'm slowly going mad with Masterpages and the FindControl. After a couple days of figuring out how to use the FindControl command from within a Masterpage, I still can't explain...
11
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I am trying to get the text of an item in a GridView, but am doing something wrong. Can someone help me with the correct C# statement I need? Below is my GridView and my attempt to get the control....
5
by: daniel.hedz | last post by:
I am generating a usercontrol dynamically successfully, but when I try to find that usercontrol I get a type mismatch. This is what I am doing: //Loading my usercontrol...
1
by: Dan | last post by:
Hi, I created a custom control (ParentCustomControl) which is using a custom template (implementing ITemplate interface), in the instantiateIn method of this template I create all the controls I...
14
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I have created a UserControl ("MyUC"). I've put a bunch of instances of that control on a Page ("Defaul.aspx"). The control works fine. Now, I want to be able to use "FindControl()" from...
7
by: AAaron123 | last post by:
Me.FindControl("MissionScheduleID"), below returns null. Do you know what I'm doing wrong? Thanks ***In my .aspx file I have: asp:Content ID="Content3"...
4
by: Hillbilly | last post by:
Maybe this is or isn't some kind of bug but it sure is goofy and remains a mystery that really has me puzzled for two reasons... // goofy syntax functions as expected... Panel finalStepButton =...
9
by: AAaron123 | last post by:
I'm this far in determining the correct code to find a textbox I need to set. ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.