473,756 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re-using DropDown Lists?

Hi All

I have a question about re-using a drop downlist box across several
questions on a questionaire like form. I will include code after some
explaination.

I thought i could make a dropdownlist box object global and re-use it as
needed if i did not destroy the object, but it doesnt seem to be working out
for me.

In the Class file i declare the object as follows:
Private ddlListBoxMulti As DropDownList

On Page Load i call the Sub to create the DropDownList Box

Get_MultiDDL()

I have changed this proceedure from a sub to function, but previously it was
a sub that created the DropDown List box:

Public Sub Get_MultiDDL()
'(a Note: SQLHelper is imported from another Assembly and is used as a
datareader)

Dim drDDLValues As SqlHelper
Dim drDDLValuesList As SqlDataReader
Dim i As Integer = 0
ddlListBoxMulti = New DropDownList

i = 0

'Call DB for Values needed
drDDLValuesList =
drDDLValues.Exe cuteReader(Conf igurationSettin gs.AppSettings( "SQLServer" ),
CommandType.Sto redProcedure, "csp_SELECT_Ans wer_Multi")
'Add first item blank
ddlListBoxMulti .Items.Add(" ")
ddlListBoxMulti .Items(i).Value () = 0

i += 1
'Loop to get all values needed into DropDownList
Do While drDDLValuesList .Read()
ddlListBoxMulti .Items.Add(drDD LValuesList.Get String(1))
ddlListBoxMulti .Items(i).Value () = drDDLValuesList .GetInt32(0)
i += 1
Loop

i = 0
drDDLValuesList .Close()
drDDLValuesList = Nothing
drDDLValues = Nothing

End sub
Then, i have to construct a table of twenty questions, the first twenty are
an intial interview, then a second group of twenty for a thirty day
evaluation, all nicely tucked into table cells. For brevity, i will only
include the section of code that is in question.
What i am trying to accomplish is to make one call to the function and
re-use the DropDownList box everytime i need it as follows and remeber for
brevity i only toook out the code in question, this code appears in a loop
that gets the questions from
the SQLDB:
cell = New TableCell
'******this code does not work
cell.Controls.A dd(ddlListBoxMu lti)
ddlListBoxMulti .ID = "ddlMIntial " & i.ToString()
ddlListBoxMulti .Width = Unit.Pixel(150)
cell.Attributes .Add("align", "center")
row.Cells.Add(c ell)

cell = New TableCell
cell.Controls.A dd(Get_MultiDDL ())
ddlListBoxMulti .ID = "ddlM30Day" & i.ToString()
ddlListBoxMulti .Width = Unit.Pixel(150)
cell.Attributes .Add("align", "center")
row.Cells.Add(c ell)
I realize this is long but why does the DropDownlist seem to disappear and
not get rendered using the second method

Any help greatly appreciated

TIA

--
The Mighty Thor Lives
http://www.themightythor.com
Nov 17 '05 #1
4 1340
Maybe I'm missing something, but if you want to get 20 cells with
DropDownList in each you need to create 20 DropDownLists. What you're doing
is you're creating a new DropDownList in your Get_MultiDDL(), but you're
assigning it to a global variable. The only thing you're reusing is the
ddlListBoxMulti pointer. The next time you call your Sub the ddlListBoxMulti
gets the new object and the old object is lost. So when it comes time to
render you will only have your last DropDownList.

If you want to reuse the logic of creating DropDownLists make your
Get_MultiDDL() a function returning DropDownList:

Public Function Get_MultiDDL() as DropDownList

Dim drDDLValues As SqlHelper
Dim drDDLValuesList As SqlDataReader
Dim i As Integer = 0
Dim ddl as New DropDownList

i = 0

'Call DB for Values needed
drDDLValuesList =
drDDLValues.Exe cuteReader(Conf igurationSettin gs.AppSettings( "SQLServer" ),
CommandType.Sto redProcedure, "csp_SELECT_Ans wer_Multi")
'Add first item blank
ddl.Items.Add(" ")
ddl.Items(i).Va lue() = 0

i += 1
'Loop to get all values needed into DropDownList
Do While drDDLValuesList .Read()
ddl.Items.Add(d rDDLValuesList. GetString(1))
ddl.Items(i).Va lue() = drDDLValuesList .GetInt32(0)
i += 1
Loop

i = 0
drDDLValuesList .Close()
drDDLValuesList = Nothing
drDDLValues = Nothing

return ddl

End Function
Then you can simply do cell.Controls.A dd(Get_MultiDDL ()) in your second loop
Nov 17 '05 #2
Maybe I'm missing something, but if you want to get 20 cells with
DropDownList in each you need to create 20 DropDownLists. What you're doing
is you're creating a new DropDownList in your Get_MultiDDL(), but you're
assigning it to a global variable. The only thing you're reusing is the
ddlListBoxMulti pointer. The next time you call your Sub the ddlListBoxMulti
gets the new object and the old object is lost. So when it comes time to
render you will only have your last DropDownList.

If you want to reuse the logic of creating DropDownLists make your
Get_MultiDDL() a function returning DropDownList:

Public Function Get_MultiDDL() as DropDownList

Dim drDDLValues As SqlHelper
Dim drDDLValuesList As SqlDataReader
Dim i As Integer = 0
Dim ddl as New DropDownList

i = 0

'Call DB for Values needed
drDDLValuesList =
drDDLValues.Exe cuteReader(Conf igurationSettin gs.AppSettings( "SQLServer" ),
CommandType.Sto redProcedure, "csp_SELECT_Ans wer_Multi")
'Add first item blank
ddl.Items.Add(" ")
ddl.Items(i).Va lue() = 0

i += 1
'Loop to get all values needed into DropDownList
Do While drDDLValuesList .Read()
ddl.Items.Add(d rDDLValuesList. GetString(1))
ddl.Items(i).Va lue() = drDDLValuesList .GetInt32(0)
i += 1
Loop

i = 0
drDDLValuesList .Close()
drDDLValuesList = Nothing
drDDLValues = Nothing

return ddl

End Function
Then you can simply do cell.Controls.A dd(Get_MultiDDL ()) in your second loop
Nov 17 '05 #3
Hi Thanks For your answer. I had a;ready changed it to what you suggested
before reading your post.

The Reason i wanted one DropDownList is because all 20 questions can be
answered by the contents od the DDL

so i was trying to reuse it over and over again.

Silly me, I did figure it out and i do thank you for your help!! Sometimes
you just shouldn't code on a 24 hour Diet Coke Buzz!!
--
The Mighty Thor Lives
http://www.themightythor.com
"Michael Per" <me@nospam.co m> wrote in message
news:8L******** *********@twist er.nyc.rr.com.. .
Maybe I'm missing something, but if you want to get 20 cells with
DropDownList in each you need to create 20 DropDownLists. What you're doing is you're creating a new DropDownList in your Get_MultiDDL(), but you're
assigning it to a global variable. The only thing you're reusing is the
ddlListBoxMulti pointer. The next time you call your Sub the ddlListBoxMulti gets the new object and the old object is lost. So when it comes time to
render you will only have your last DropDownList.

If you want to reuse the logic of creating DropDownLists make your
Get_MultiDDL() a function returning DropDownList:

Public Function Get_MultiDDL() as DropDownList

Dim drDDLValues As SqlHelper
Dim drDDLValuesList As SqlDataReader
Dim i As Integer = 0
Dim ddl as New DropDownList

i = 0

'Call DB for Values needed
drDDLValuesList =
drDDLValues.Exe cuteReader(Conf igurationSettin gs.AppSettings( "SQLServer" ),
CommandType.Sto redProcedure, "csp_SELECT_Ans wer_Multi")
'Add first item blank
ddl.Items.Add(" ")
ddl.Items(i).Va lue() = 0

i += 1
'Loop to get all values needed into DropDownList
Do While drDDLValuesList .Read()
ddl.Items.Add(d rDDLValuesList. GetString(1))
ddl.Items(i).Va lue() = drDDLValuesList .GetInt32(0)
i += 1
Loop

i = 0
drDDLValuesList .Close()
drDDLValuesList = Nothing
drDDLValues = Nothing

return ddl

End Function
Then you can simply do cell.Controls.A dd(Get_MultiDDL ()) in your second loop

Nov 17 '05 #4
Hi Thanks For your answer. I had a;ready changed it to what you suggested
before reading your post.

The Reason i wanted one DropDownList is because all 20 questions can be
answered by the contents od the DDL

so i was trying to reuse it over and over again.

Silly me, I did figure it out and i do thank you for your help!! Sometimes
you just shouldn't code on a 24 hour Diet Coke Buzz!!
--
The Mighty Thor Lives
http://www.themightythor.com
"Michael Per" <me@nospam.co m> wrote in message
news:8L******** *********@twist er.nyc.rr.com.. .
Maybe I'm missing something, but if you want to get 20 cells with
DropDownList in each you need to create 20 DropDownLists. What you're doing is you're creating a new DropDownList in your Get_MultiDDL(), but you're
assigning it to a global variable. The only thing you're reusing is the
ddlListBoxMulti pointer. The next time you call your Sub the ddlListBoxMulti gets the new object and the old object is lost. So when it comes time to
render you will only have your last DropDownList.

If you want to reuse the logic of creating DropDownLists make your
Get_MultiDDL() a function returning DropDownList:

Public Function Get_MultiDDL() as DropDownList

Dim drDDLValues As SqlHelper
Dim drDDLValuesList As SqlDataReader
Dim i As Integer = 0
Dim ddl as New DropDownList

i = 0

'Call DB for Values needed
drDDLValuesList =
drDDLValues.Exe cuteReader(Conf igurationSettin gs.AppSettings( "SQLServer" ),
CommandType.Sto redProcedure, "csp_SELECT_Ans wer_Multi")
'Add first item blank
ddl.Items.Add(" ")
ddl.Items(i).Va lue() = 0

i += 1
'Loop to get all values needed into DropDownList
Do While drDDLValuesList .Read()
ddl.Items.Add(d rDDLValuesList. GetString(1))
ddl.Items(i).Va lue() = drDDLValuesList .GetInt32(0)
i += 1
Loop

i = 0
drDDLValuesList .Close()
drDDLValuesList = Nothing
drDDLValues = Nothing

return ddl

End Function
Then you can simply do cell.Controls.A dd(Get_MultiDDL ()) in your second loop

Nov 17 '05 #5

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

Similar topics

1
4323
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6429
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4101
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
11
4010
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
18534
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function blocks until something.exe terminates. Just what I /don't/ want. (Wouldn't an & be nice here! Sigh) I need something.exe to disconnect and run in the background while I
1
3704
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with sockets??
8
4417
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
1
3638
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id NOT IN ( SELECT manufacturers_id FROM products )
1
3829
by: Clarice Almeida Hughes | last post by:
tenho um index onde tenho o link pro arq css, como sao visualizados pelo include todas as paginas aderem ao css linkado no index. so q eu preciso de alguns links com outras cores no css, o q devo fazer?
2
5313
by: JW | last post by:
I wanted have this as part of a flood control script: <? echo ("Flood control in place - please wait " . $floodinterval . " seconds between postings."); sleep(5); // go back two pages echo "<script>window.history.go(-2);</script>"; exit; ?>
0
9456
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
10034
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
9872
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...
0
9713
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...
0
8713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
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
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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.