Ahoj,
mam problem s pridavanim polozek do generickeho listu,
problem se projevuje tak, ze kdyz vlozim do listu 1. polozku, je vse ok, ale kdyz vlozim druhou, prvni i druha maji hodnoty te druhe a tak to pokracuje, jen pribudne dalsi zaznam ale hodnoty vzdy z toho posledniho.
kod vypada takhle (asp.net 4.0):
Partial Class _Default
Inherits System.Web.UI.Page
<Serializable()>
Public Class Product
Shared Property Material As String
Shared Property Type As String
Shared Property ImageURL As String
End Class
Public Property CurrentSelection() As Product
Get
Dim text As Product = ViewState("Product")
If text IsNot Nothing Then
Return text
Else
Dim Ntext As New Product
ViewState("Product") = Ntext
Return Ntext
End If
End Get
Set(ByVal value As Product)
ViewState("Product") = value
End Set
End Property
Public Property Products() As List(Of Product)
Get
Dim text As List(Of Product) = ViewState("Products")
If text IsNot Nothing Then
Return text
Else
Dim Ntext As New List(Of Product)
ViewState("Products") = Ntext
Return Ntext
End If
End Get
Set(ByVal value As List(Of Product))
ViewState("Products") = value
End Set
End Property
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim First As New Product
First.Material = "111"
First.Type = ""
First.ImageURL = ""
Dim Second As New Product
Second.Material = "2222"
Second.Type = ""
Second.ImageURL = ""
Products.Add(First)
Products.Add(Second)
For Each item In Products
Response.Write(item.Material & "</br>")
Next
End Sub
End Class