troubleshooting Question

Finding an Existing item in an array and Add them

Avatar of fosiul01
fosiul01Flag for United Kingdom of Great Britain and Northern Ireland asked on
.NET ProgrammingASP.NET
27 Comments1 Solution523 ViewsLast Modified:
Hi , this is an existing question : https://www.experts-exchange.com/Microsoft/Development/.NET/Visual_Studio_.NET_2005/Q_23419970.html

If any one can use my existing code and advise me, how i will find an existing item in an array  .

if item is already in their then it will Add the amount with the existing item.
if its new item , it will add in the array thats all..



''''''''''''''''''''''''''''''
default.aspx( code behind)
''''''''''''''''''''''''''''''
Partial Class _Default
    Inherits System.Web.UI.Page
    Private al As ArrayList
 
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Obj As Add = New Add
        ' Bellow code is holing data is comming from textbox1.text
        Obj.Name = TextBox1.Text
        Obj.Id = TextBox2.Text
        Obj.Amount = TextBox4.Text
 
        '' Need to check if Same Id is already there or not. if yes, then it will Add the amount with the old ID
        Dim X As Integer  <<-----------------------------------
        For X = 0 To al.Count - 1
            if al("Id) = 
        Next
        'Inserting all Record in object in ArrayList.
        al.Add(Obj)
        Session("al") = al
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("al") IsNot Nothing Then
            al = CType(Session("al"), ArrayList)
        Else
            al = New ArrayList
        End If
 
    End Sub
 
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        GridView1.DataSource = al
        GridView1.DataBind()
 
    End Sub
End Class
 
'''''''''''''''''
add.vb(class)
''''''''''''''''
Imports Microsoft.VisualBasic
 
Public Class Add
    Private _StrName As String
    Private _IntId As Integer
    Private _IntAmount As Integer
 
 
    Public Property Name() As String
        Get
            Return _StrName
        End Get
        Set(ByVal Value As String)
            _StrName = Value
        End Set
    End Property
    Public Property Id() As Integer
        Get
            Return _IntId
        End Get
        Set(ByVal value As Integer)
            _IntId = value
        End Set
    End Property
 
    Public Property Amount() As Integer
        Get
            Return _IntAmount
        End Get
        Set(ByVal value As Integer)
            _IntAmount = value
        End Set
    End Property
End Class
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 27 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 27 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros