I have a addhandler that controls the events of a dropdownlist that is being built on the fly. There could be one DDL ro multiple depending on what is returned from the DB. When the user selects one of the three options in the DDL, then the results will create either a TxtBox or another DDL.
The issue that I am having is that if I have 3 DDL's and the user selects something from the first one, it hits the addhandler sub routine, and it creates either a txtbox or ddl. It reloads the page with the new control. Here is where it gets tricky....if the user selects something with in the second DDL and it hits the addhandler again..only this time when it reloads the page it doesn't keep the first control that is built, it removes it and builds the new control.
I'm puzzled on how I can keep each control that is built on the page? If you notice below, the user can change each one of the Function DDL's and in turn each one should build its own Value txtbox or ddl. It does build the new control but I can't keep the previous control that was built.
Form Layout:
Lot: 722-7724 |
Rec. Qty: |
|
Function: |
NONE ALWAYS MULTIPLIER |
Value: |
Bed-in-a-Bag Twin Sheet Set |
A 2005 |
01/09/2005 - 08/27/2005 |
|
Lot: 722-7726 |
Rec. Qty: |
|
Function: |
NONE ALWAYS MULTIPLIER |
Value: |
|
Bed-in-a-Bag Full Sheet Set |
A 2005 |
01/09/2005 - 08/27/2005 |
|
Lot: 722-7728 |
Rec. Qty: |
|
Function: |
NONE ALWAYS MULTIPLIER |
Value |
CODE (LoadPage where the DDL Function is being built) :
'Add DropDown List Items for ddlFunction
ddlFunction = New DropDownList
ddlFunction.AutoPostBack = True
ddlFunction.Items.Add(New ListItem(""))
ddlFunction.Items.Add(New ListItem("NONE"))
ddlFunction.Items.Add(New ListItem("ALWAYS"))
ddlFunction.Items.Add(New ListItem("MULTIPLIER"))
tr.Cells.Add(CreateDropDownListCell(ddlFunction, "ddlFunction" & strText, , 85, Css.Style.DefaultText))
'Create AddHandler for ddlFunction
AddHandler ddlFunction.SelectedIndexChanged, AddressOf ProcessDDLFunction
'Display Label name for TextBox
tr.Cells.Add(CreateTextCell("Value:", Css.Style.DefaultTextBold, , False, HorizontalAlign.Right))
'Display the Value field, either textbox or dropdown
strTRID = Right(tr.ID, 8)
strCurLotNum = CType(Session("strLotNum"), String)
If strTRID = CType(Session("strLotNum"), String) And CType(ddlFunction.SelectedIndex, String) <> CType(Session("strIndex"), String) Then
If strText = strCurLotNum Then
tr.Cells.Add(CType(Session("tcXCell"), TableCell))
End If
End If
tblMain.Rows.Add(tr)
CODE (Sub Routine for AddHandler, where new control is being built):
'dllFunction = NONE, create TextBox(txtValue) default to ZERO
If CType(sender, DropDownList).SelectedIndex = 1 Then
txtValue = New TextBox
txtValue.AutoPostBack = False
tcXCell = CreateTextBoxCell(txtValue, "txtValue" & Right(CType(sender, DropDownList).ID, 8), "0", , 60, , Css.Style.DefaultText)
Session("tcXCell") = tcXCell
ElseIf CType(sender, DropDownList).SelectedIndex = 2 Then
'dllFunction = NONE, create TextBox(txtValue) default to blank
txtValue = New TextBox
txtValue.AutoPostBack = False
tcXCell = CreateTextBoxCell(txtValue, "txtValue" & Right(CType(sender, DropDownList).ID, 8), , , 60, , Css.Style.DefaultText)
Session("tcXCell") = tcXCell
ElseIf CType(sender, DropDownList).SelectedIndex = 3 Then
'dllFunction = ALWAYS, create DropDown List with default values
ddlValue = New DropDownList
ddlValue.AutoPostBack = False
tcXCell = CreateDropDownListCell(ddlValue, "ddlValue" & Right(CType(sender, DropDownList).ID, 8), , 85, Css.Style.DefaultText)
Session("tcXCell") = tcXCell
End If
Session("strIndex") = CType(sender, DropDownList).SelectedIndex
strLotNum = Right(CType(sender, DropDownList).ID, 8)
Session("strLotNum") = strLotNum
Thanks in advance for any help!
Adrian