Please tell me what I am missing here....
Why would my Employees object be Null where the datasource is set? (This is in the initial page_load.)
Why would my Employees object be Null where the datasource is set? (This is in the initial page_load.)
Code:
[blue]Partial Class [black]_Default[/black]
Inherits [black]System.Web.UI.Page[/black]
Protected Sub [black]Page_Load([/black]ByVal [black]sender[/black] As Object, ByVal [black]e[/black] As [black]System.EventArgs)[/black] Handles Me[black].Load[/black]
If Not [black]Page.IsPostBack[/black] Then
Dim [black]Employees[/black] As New [black]Collection
Employees.Add([/black]New [black]Employee("George", "Washington"))
Employees.Add([/black]New [black]Employee("John", "Adams"))
Employees.Add([/black]New [black]Employee("Thomas", "Jefferson"))
GridView5.DataSource = Employees [green]' NullReferenceException at this point[/green]
GridView5.DataBind()[/black]
End If
End Sub
End Class
Public Class [black]Employee[/black]
Private [black]_FirstName[/black] As String
Public Property [black]FirstName[/black]() As String
Get
Return [black]_FirstName[/black]
End Get
Set(ByVal [black]Value[/black] As String)
[black]_FirstName = Value[/black]
End Set
End Property
Private [black]_LastName[/black] As String
Public Property [black]LastName[/black]() As String
Get
Return [black]_LastName[/black]
End Get
Set(ByVal [black]Value[/black] As String)
[black]_LastName = Value[/black]
End Set
End Property
Public Sub New(ByVal [black]FName[/black] As String, ByVal [black]LName[/black] As String)
[black]_FirstName = FName
_LastName = LName[/black]
End Sub
End Class[/blue]