Can't access databound dropdownlist properties in user control

Discussion in 'ASP .Net' started by =?Utf-8?B?QVNQIERldmVsb3Blcg==?=, Nov 8, 2005.

  1. 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
    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=, Nov 8, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Max2006
    Replies:
    2
    Views:
    502
    Max2006
    Jul 13, 2007
  2. rodchar
    Replies:
    2
    Views:
    527
    rodchar
    Dec 4, 2007
  3. rodchar
    Replies:
    0
    Views:
    379
    rodchar
    Nov 26, 2007
  4. Manu
    Replies:
    0
    Views:
    159
  5. Lagrange
    Replies:
    1
    Views:
    544
    Lagrange
    Jan 17, 2009
Loading...

Share This Page