Anonymní profil MartinNNN – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Anonymní profil MartinNNN – Programujte.comAnonymní profil MartinNNN – Programujte.com

 

Příspěvky odeslané z IP adresy 178.41.97.–

MartinNNN
.NET › generic list, add, a stejne…
17. 1. 2011   #137913

zkusil jsem tohle, pocet itemu narusta, ale kazdy ma hodnoty toho posledniho




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 = "1111"
First.Type = ""
First.ImageURL = ""

Products.Add(First)

For Each item In Products
Response.Write(item.Material & "</br>")
Next
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Second As New Product
Second.Material = "2222"
Second.Type = ""
Second.ImageURL = ""

Products.Add(Second)

For Each item In Products
Response.Write(item.Material & "</br>")
Next
End Sub

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim Third As New Product
Third.Material = "3333"
Third.Type = ""
Third.ImageURL = ""

Products.Add(Third)

For Each item In Products
Response.Write(item.Material & "</br>")
Next
End Sub

End Class




MartinNNN
.NET › generic list, add, a stejne…
17. 1. 2011   #137912

v priloze je projekt

MartinNNN
.NET › generic list, add, a stejne…
17. 1. 2011   #137908

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

 

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý