G
Guest
I created a very simple user control that has one dropdownlist. I bind the
dropdownlist to database results on load in an ascx file. I would like to do
be able to change the selectedindex from the aspx page. So I created a
property in the ascx file to expose the selected index property. However,
when I attempt to change the selectedindex I get the error: object is not set
to an instance of an object". Any help would be greatly appreciated.
'**************************Aspx page ***************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim tempUserControl = Page.LoadControl("populatedropdown.ascx")
tempUserControl.myProp = "myval"
end sub
'**************************Ascx page *****************
Public Property myProp() As String
Get
Return dropdownlist1.SelectedIndex
End Get
Set(ByVal Value As String)
DropDownList1.Items.FindByValue(Value).Selected = True
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Call populatedrowdown()
End Sub
Function populatedrowdown()
Dim vArray As DataTable
Dim dt As New DataTable()
Dim dr As DataRow
Dim ozaweb As New plnwrapper.wrapper()
dt = ozaweb.GetVillageTypes
DropDownList1.DataSource = dt
DropDownList1.DataTextField = dt.Columns(1).ColumnName
DropDownList1.DataValueField = dt.Columns(0).ColumnName
DropDownList1.DataBind()
End Function
dropdownlist to database results on load in an ascx file. I would like to do
be able to change the selectedindex from the aspx page. So I created a
property in the ascx file to expose the selected index property. However,
when I attempt to change the selectedindex I get the error: object is not set
to an instance of an object". Any help would be greatly appreciated.
'**************************Aspx page ***************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim tempUserControl = Page.LoadControl("populatedropdown.ascx")
tempUserControl.myProp = "myval"
end sub
'**************************Ascx page *****************
Public Property myProp() As String
Get
Return dropdownlist1.SelectedIndex
End Get
Set(ByVal Value As String)
DropDownList1.Items.FindByValue(Value).Selected = True
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Call populatedrowdown()
End Sub
Function populatedrowdown()
Dim vArray As DataTable
Dim dt As New DataTable()
Dim dr As DataRow
Dim ozaweb As New plnwrapper.wrapper()
dt = ozaweb.GetVillageTypes
DropDownList1.DataSource = dt
DropDownList1.DataTextField = dt.Columns(1).ColumnName
DropDownList1.DataValueField = dt.Columns(0).ColumnName
DropDownList1.DataBind()
End Function