D
Dylan Mines
Hi
I'm really confused about the behaviour of a drop down list that is
populated from a database table.
The problem that i was getting was the value (selected from my dropdown
list) was always being added to the database as '0' no matter what item was
selected.
To try and debug i wrote the selected value to a label at the onclick event
but i just get the 'object reference not set to an instance of an object'
error message. What does this error mean in this case?
My code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
SqlDataAdapter1.Fill(DataSet1)
DropDownList1.DataSource = DataSet1
DropDownList1.DataTextField = "typeDescription"
DropDownList1.DataValueField = "typeCode"
DropDownList1.DataBind()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label1.Text = DropDownList1.SelectedItem.Text
Label2.Text = DropDownList1.SelectedItem.Value
End Sub
The error occurs at the point where it attempts to write to the first label.
This code is as simple as it gets but i still get the error. What is going
on?
Can you also tell me why this error occurs so often and without any
explanation? I find it really frustrating because i see this error as
meaning 'there is an error and i'm not going to tell you what it is'. Any
help in how to diagnose this common error would be much appreciated.
Thanks,
Dylan
I'm really confused about the behaviour of a drop down list that is
populated from a database table.
The problem that i was getting was the value (selected from my dropdown
list) was always being added to the database as '0' no matter what item was
selected.
To try and debug i wrote the selected value to a label at the onclick event
but i just get the 'object reference not set to an instance of an object'
error message. What does this error mean in this case?
My code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
SqlDataAdapter1.Fill(DataSet1)
DropDownList1.DataSource = DataSet1
DropDownList1.DataTextField = "typeDescription"
DropDownList1.DataValueField = "typeCode"
DropDownList1.DataBind()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label1.Text = DropDownList1.SelectedItem.Text
Label2.Text = DropDownList1.SelectedItem.Value
End Sub
The error occurs at the point where it attempts to write to the first label.
This code is as simple as it gets but i still get the error. What is going
on?
Can you also tell me why this error occurs so often and without any
explanation? I find it really frustrating because i see this error as
meaning 'there is an error and i'm not going to tell you what it is'. Any
help in how to diagnose this common error would be much appreciated.
Thanks,
Dylan