Can't access databound dropdownlist properties in user control

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top