View Single Post
  #5 (permalink)  
Old September 1st, 2005, 11:14 PM
vvv vvv is offline
Registered User
 
Join Date: Sep 2005
Location: Pontian, Johor, Malaysia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vvv Send a message via MSN to vvv Send a message via Yahoo to vvv
Default

hello melvik,

i create a dropdownlist in my webform and my method is same as yours but when i try to select the value in the dropdownlist the dropdownlist will give me error "Object reference not set to an instance of an object." i have do a testing with ur code, the same error occur.
below is my code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        If Not IsPostBack Then


            myConnection = New SqlConnection("Server=p866;uid=sa;pwd=;Database=su rvey")
            myCommand = New SqlCommand("Select form_id From form", myConnection)
            myConnection.Open()
            DropDownList1.DataSource = myCommand.ExecuteReader()
            DropDownList1.DataTextField = "form_id"
            DropDownList1.DataBind()
            myConnection.Close()
        End If
End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        TextBox1.Text = DropDownList1.SelectedItem.Value
End Sub
Please help if u could. thanks




wei
Reply With Quote