I get a runtime error 'NullReferenceException: Object reference not set
to an instance of an object' when I attempt to execute sub UpdGrd() in
the Page_Load event. UpdGrd() basically creates a grid (works OK) and
attempts to read the selected item of dropdown box 'ddnEmp_Emp'. The
idea is to add this value to the grid's title. (Default value should be
'All'.)
Event ddnEmp_Emp_SelectedIndexChanged() works OK and returns the
correct value.
Question: Why can't I read the selectedItem.value at load-up time? The
value should not be null. Some posts I read suggest to instantiate the
dropdown. How do I do this?
Thanks for any hints, Mark
Code snippet:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
ddnEmp_Emp.Text = "0" 'Select All
End If
UpdGrd()
End Sub
Sub UpdGrd()
Dim strEmp As String = ddnEmp_Emp.SelectedValue 'Compiler accepts
this!
Dim strEmpName As String = "" 'Input value
....
If Not IsNothing(ddnEmp_Emp.SelectedItem.ToString) Then strEmpName =
ddnEmp_Emp.SelectedItem.ToString <--- Error!
Response.Write("ddnEmp_Emp: " & strEmpName)
....
End Sub