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