Private Property ListEmployee As List(Of Employee)
Get
Return Session(Me.GetType.Name)
End Get
Set(ByVal value As List(Of Employee))
Session(Me.GetType.Name) = value
End Set
End Property
Private ReadOnly Property objEmployee As Employee
Get
Dim obj As New Employee
obj.User_ID = txtUserID.Text.Trim
obj.Name = txtName.Text.Trim
obj.Position = txtPosition.Text.Trim
Return obj
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnAddtoTable_Click(sender As Object, e As EventArgs) Handles btnAddtoTable.Click
ListEmployee.Add(objEmployee) 'error at here
gvResult.DataSource = ListEmployee
gvResult.DataBind()
End Sub
末级
我尝试数据(类员工)加入到ListEmployee为我的代码(员工列表),然后显示在gridview上,但我得到一个错误。
您是否尝试过踏进你的代码,看看什么'ListEmployee'值和'objEmployee'是?很可能'ListEmployee'不在'Session'中。 – Tim
ListEmployee ==> value = count = 0(错误无子女可用)objEmployee ==>具有值 – user3534404