I have it setup so that when a user selects an item from a DropdownList, that some DropdownLists are dynamically created, based on the results from the Database that are returned after selecting the item in the first DropDownList.
Then, I have a button that takes the data and saves it to an object I've created for this, and I try to iterate through the Controls of the Placeholder that I added the DropdownList controls to.
However, the Placeholder says there are no controls in it, when I press the button, but I can obviously see them there.
I'm a little confused as to why this happening. I've seen some tutorials but they don't seem to be helping at all. Here is some code:
When a "Pilot" is selected, I get all of the Upgrade Types that that "Pilot" has access to, then I create a DropdownList for each type of Upgrade with all the actual Upgrades of that Type:
Then, when the "Add Squad Member" button is pressed, I am trying to iterate through the controls, pick out any DropdownLists and get the values from them and add them to a List Of in an object for the Pilot info:
But, the controls supposedly don't exist and no values get added to the List(Of).
Then, I have a button that takes the data and saves it to an object I've created for this, and I try to iterate through the Controls of the Placeholder that I added the DropdownList controls to.
However, the Placeholder says there are no controls in it, when I press the button, but I can obviously see them there.
I'm a little confused as to why this happening. I've seen some tutorials but they don't seem to be helping at all. Here is some code:
When a "Pilot" is selected, I get all of the Upgrade Types that that "Pilot" has access to, then I create a DropdownList for each type of Upgrade with all the actual Upgrades of that Type:
VB Code:
For Each u As UpgradeTypeList In upgrades Dim lbl As New Label Dim ddl As New DropDownList ddl.AutoPostBack = False Dim TR_Row As New TableRow Dim TD_Label, TD_Dropdown As New TableCell TD_Label.Attributes.Add("style", "padding: 2px;") TD_Dropdown.Attributes.Add("style", "padding: 2px;") TD_Label.Attributes.Add("align", "right") lbl.Text = String.Format("{0}: ", u.Type) Dim ucList As List(Of UpgradeDropdown) = (From x In db.tblCards_Upgrades Where x.Type = u.ID Select New UpgradeDropdown With { .Name = String.Format("{0} ({1})", x.Title, x.PointCost), .UpgradeID = x.UpgradeID }).ToList ddl.Items.Add(New ListItem("", 0)) For Each x As UpgradeDropdown In ucList ddl.Items.Add(New ListItem(x.Name, x.UpgradeID)) Next TD_Label.Controls.Add(lbl) TD_Dropdown.Controls.Add(ddl) TR_Row.Controls.Add(TD_Label) TR_Row.Controls.Add(TD_Dropdown) rowUpgrades.Controls.Add(TR_Row) Next
Then, when the "Add Squad Member" button is pressed, I am trying to iterate through the controls, pick out any DropdownLists and get the values from them and add them to a List Of in an object for the Pilot info:
VB Code:
Protected Sub btnAddSquadMember_Click(sender As Object, e As EventArgs) Handles btnAddSquadMember.Click For Each c As Control In rowUpgrades.Controls If TypeOf c Is DropDownList Then Dim DoesExist As Boolean = False For Each x As SquadMember_Upgrade In Global_asax.TempPilot.Upgrades If x.ID = sender.ID Then DoesExist = True End If If DoesExist Then x.Name = sender.SelectedValue Exit Sub End If Next Dim newUpgrade As New SquadMember_Upgrade newUpgrade.ID = sender.ID newUpgrade.Name = sender.SelectedValue Global_asax.TempPilot.Upgrades.Add(newUpgrade) End If Next Global_asax.SquadMembers.Add(Global_asax.TempPilot) End Sub
But, the controls supposedly don't exist and no values get added to the List(Of).