Dynamic ArrayList Datagrid

Posted on 2009-04-20
Last Modified: 2012-05-06
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



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


            Return False

        End If

End Function

Protected Sub BindItemDG()

        ItemDataGrid.DataSource = ItemDetails


        Table_DG.Visible = True

End Sub

Open in new window

Question by:AsishRaj
    LVL 18

    Expert Comment

    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
    LVL 9

    Author Comment

    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.
    LVL 18

    Accepted Solution

    Try this:
    Insert after line #40:
    Session("ItemDetails") = ItemDetails

    Then add Page_Load event handler:
    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      If Not IsPostBack Then
        Me.ItemDetails = New ArrayList()
        Me.ItemDetails = Session("ItemDetails")
      End If
    End Sub
    LVL 9

    Author Closing Comment

    Will work until i find a better Solution

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now