G
Guest
Hello All,
I am developing a webform which creates ArrayLists of people's names and
addresses (the values are retrieved from an xml file) and dynamically drops a
user control onto the webform and populates it with the required names. Once
the user selects a name, the webform will then drop another user control (the
same control) onto itself and populate it with the selected name's addresses.
The user control is a combination of an asp:label and an asp:dropdownlist.
(The asp:label just indicates what the contents of the dropdownlist are -
name, address, whatever.)
The problem is this: I can drop the user control with the names onto the
page without any difficulty. The list of names appears for the user to
select from.
The AddHandler doesn't seem to connect the dropdownlist event with the
selection being changed. I've even tried to comment out the Addhandler code
and use the actual handler created by VS Studio instead:
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
m_SelectedId = Integer.Parse(CType(sender,
DropDownList).SelectedItem.Value)
End Sub
Again, no luck.
I need to retrieve the selected and use it to retrieve the person's addresses.
I would apprciate any help with this that you could offer. This one is
stumping me.
Here is the code in the webform which instantiates and adds the the user
control to a tablecell in a table on the webform:
Dim UControl As AugmentedDropDownList =
CType(LoadControl("../UserControls/AugmentedDropDownList.ascx"),
AugmentedDropDownList)
UControl.PopulateDropDownList(Control.Attributes("name").Value, DropDownNode)
NewCell.Controls.Add(UControl)
Here is the code in the entire User Control:
Imports System.Xml
Public Class AugmentedDropDownList
Inherits System.Web.UI.UserControl
Private m_SelectedId As Integer
Public Sub PopulateDropDownList(ByVal ListCaption As String, ByVal
ListItems As XmlNode)
Label1.Text = ListCaption
Dim Items As XmlNodeList = ListItems.SelectNodes("Items/Item")
For Each Item As XmlNode In Items
Dim li As New ListItem
li.Value = Item.Attributes("id").Value
li.Text = Item.Attributes("value").Value
DropDownList1.Items.Add(li)
Next
m_SelectedId = 0
AddHandler DropDownList1.SelectedIndexChanged, AddressOf
DropDownHandler
End Sub
Private Sub DropDownHandler(ByVal sender As System.Object, ByVal e As
System.EventArgs)
m_SelectedId = Integer.Parse(CType(sender,
DropDownList).SelectedItem.Value)
End Sub
End Class
TIA,
I am developing a webform which creates ArrayLists of people's names and
addresses (the values are retrieved from an xml file) and dynamically drops a
user control onto the webform and populates it with the required names. Once
the user selects a name, the webform will then drop another user control (the
same control) onto itself and populate it with the selected name's addresses.
The user control is a combination of an asp:label and an asp:dropdownlist.
(The asp:label just indicates what the contents of the dropdownlist are -
name, address, whatever.)
The problem is this: I can drop the user control with the names onto the
page without any difficulty. The list of names appears for the user to
select from.
The AddHandler doesn't seem to connect the dropdownlist event with the
selection being changed. I've even tried to comment out the Addhandler code
and use the actual handler created by VS Studio instead:
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
m_SelectedId = Integer.Parse(CType(sender,
DropDownList).SelectedItem.Value)
End Sub
Again, no luck.
I need to retrieve the selected and use it to retrieve the person's addresses.
I would apprciate any help with this that you could offer. This one is
stumping me.
Here is the code in the webform which instantiates and adds the the user
control to a tablecell in a table on the webform:
Dim UControl As AugmentedDropDownList =
CType(LoadControl("../UserControls/AugmentedDropDownList.ascx"),
AugmentedDropDownList)
UControl.PopulateDropDownList(Control.Attributes("name").Value, DropDownNode)
NewCell.Controls.Add(UControl)
Here is the code in the entire User Control:
Imports System.Xml
Public Class AugmentedDropDownList
Inherits System.Web.UI.UserControl
Private m_SelectedId As Integer
Public Sub PopulateDropDownList(ByVal ListCaption As String, ByVal
ListItems As XmlNode)
Label1.Text = ListCaption
Dim Items As XmlNodeList = ListItems.SelectNodes("Items/Item")
For Each Item As XmlNode In Items
Dim li As New ListItem
li.Value = Item.Attributes("id").Value
li.Text = Item.Attributes("value").Value
DropDownList1.Items.Add(li)
Next
m_SelectedId = 0
AddHandler DropDownList1.SelectedIndexChanged, AddressOf
DropDownHandler
End Sub
Private Sub DropDownHandler(ByVal sender As System.Object, ByVal e As
System.EventArgs)
m_SelectedId = Integer.Parse(CType(sender,
DropDownList).SelectedItem.Value)
End Sub
End Class
TIA,