Link to home
Start Free TrialLog in
Avatar of AsishRaj
AsishRajFlag for Fiji

asked on

Dynamic ArrayList Datagrid

i have created a arraylist, class -> Code snippet

Everything works fine except only one row of record show on the datagrid. am i over-writing the details.

What m i doing wrong here. please help me to solve this
Public Class DisputeSalesItem
 
    Private m_ItemCode As String
    Private m_ItemDesc As String
    Private m_UnitPrice As Decimal
    Private m_Quantitiy As Integer
    Private m_Discount As Decimal
    Private m_LineTotal As Decimal
 
    Public Sub New(ByVal ItemCode As String, ByVal ItemDesc As String, ByVal UnitPrice As Decimal, ByVal Quantitiy As Integer, ByVal Discount As Decimal, ByVal LineTotal As Decimal)
        Me.m_ItemCode = ItemCode
        Me.m_ItemDesc = ItemDesc
        Me.m_UnitPrice = UnitPrice
        Me.m_Quantitiy = Quantitiy
        Me.m_Discount = Discount
        Me.m_LineTotal = LineTotal
    End Sub
'Property Get methods are there as well 
End Class
 
'Code Page
Protected ItemDetails As New ArrayList()
 
 Protected Sub btn_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Add.Click
        ItemDetailsCollection()
        BindItemDG()
End Sub
 
Private Function ItemDetailsCollection() As Boolean
        If ItemDetails.Add(New DisputeSalesItem(txt_ItemCode.Text.ToString, txt_ItemDesc.Text.ToString, Convert.ToDecimal(txt_UnitPrice.Text.ToString), CInt(txt_Quantity.Text), Convert.ToDecimal(txt_Discount.Text.ToString), Convert.ToDecimal(Convert.ToDecimal(txt_UnitPrice.Text.ToString) * CInt(txt_Quantity.Text) - Convert.ToDecimal(txt_Discount.Text.ToString)))) Then
            Return True
        Else
            Return False
        End If
End Function
 
Protected Sub BindItemDG()
        ItemDataGrid.DataSource = ItemDetails
        ItemDataGrid.DataBind()
        Table_DG.Visible = True
End Sub

Open in new window

Avatar of philipjonathan
philipjonathan
Flag of New Zealand image

But you have only added 1 item, which is on line #30.
If you try to call ItemDetailsCollection (line #25) twice, you'd see 2 items
Avatar of AsishRaj

ASKER

Everytime user clicks add -> btn_Add_Click Sub is being called.

So user clicks add three times it will be called, the sub will be called three time and therefore i should have three rows in my arraylist but my datagrid only show one row.
ASKER CERTIFIED SOLUTION
Avatar of philipjonathan
philipjonathan
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Will work until i find a better Solution