• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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

0
AsishRaj
Asked:
AsishRaj
  • 2
  • 2
1 Solution
 
philipjonathanCommented:
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
0
 
AsishRajAuthor Commented:
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.
0
 
philipjonathanCommented:
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()
  Else
    Me.ItemDetails = Session("ItemDetails")
  End If
End Sub
0
 
AsishRajAuthor Commented:
Will work until i find a better Solution
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now